This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2010-12-11 22:53:42

scratchU8
Scratcher
Registered: 2009-09-08
Posts: 100+

Is there such a block that can do...

I was wondering if there's a block that picks numbers from a range. Like for example: It picks a range from 1-10. (Any block in Scratch will do.)

Offline

 

#2 2010-12-11 22:54:34

4Infinity
Scratcher
Registered: 2010-12-11
Posts: 100+

Re: Is there such a block that can do...

<pick random(  )to( )
Fantastic!!


http://2.bp.blogspot.com/_TJr9oXBg5-Y/TP_C_0Gn02I/AAAAAAAAAA8/ZEE9GCe5rVM/s1600/universe00.jpg

Offline

 

#3 2010-12-11 23:02:55

scratchU8
Scratcher
Registered: 2009-09-08
Posts: 100+

Re: Is there such a block that can do...

Yes, but that picks a number. I want something that includes all numbers in that range besides just 1.

Offline

 

#4 2010-12-11 23:06:11

Kileymeister
Scratcher
Registered: 2008-04-17
Posts: 1000+

Re: Is there such a block that can do...

You could store each number in that range in a list.


I'm back, and showcasing two new* projects!  Click left or right on the image below to see!
http://img109.imageshack.us/img109/7905/part1l.pnghttp://img859.imageshack.us/img859/6417/part2bf.png

Offline

 

#5 2010-12-12 00:35:09

kayybee
Scratcher
Registered: 2009-12-07
Posts: 1000+

Re: Is there such a block that can do...

I'm not too sure what you want, I think you should word it better, so you can't blame me if I got this wrong. I'm thinking you want something that picks a number from a random range, right?
Example: make three variables, v1, v2, and v3. v3 is the final number you receive.

Note: the >* means greater than, not showing boolean.

Set variable [v1] to <pick random 1 to 10>
=Repeat until (<[v2]-[v1]> >* 0)
|Set variable [v2] to <pick random 1 to 10>
====[end repeat]===========
Set [v3] to <pick random [v1] to [v2]

Offline

 

#6 2010-12-12 10:17:16

scratchU8
Scratcher
Registered: 2009-09-08
Posts: 100+

Re: Is there such a block that can do...

Im not gonna blame you for anything. What I want is something that only allows the numbers in that range. Not just 1 number in the range. All of 'em.

Offline

 

#7 2010-12-12 10:19:52

Kileymeister
Scratcher
Registered: 2008-04-17
Posts: 1000+

Re: Is there such a block that can do...

scratchU8 wrote:

Im not gonna blame you for anything. What I want is something that only allows the numbers in that range. Not just 1 number in the range. All of 'em.

So you want a block that contains all the numbers in the range, right?
Then store them all in a list.
If you want to check if a number is in that range, have :
<if list [range] contains [#]>


I'm back, and showcasing two new* projects!  Click left or right on the image below to see!
http://img109.imageshack.us/img109/7905/part1l.pnghttp://img859.imageshack.us/img859/6417/part2bf.png

Offline

 

#8 2010-12-12 14:35:32

HD123
Scratcher
Registered: 2009-12-05
Posts: 500+

Re: Is there such a block that can do...

scratchU8 wrote:

Im not gonna blame you for anything. What I want is something that only allows the numbers in that range. Not just 1 number in the range. All of 'em.

Do you mean all of the whole numbers in that range?  If so, here is a script that puts all of those numbers in a list.

<~ when green flag clicked ~>
<~ set (n1) to (lowest number) ~>
<~ set (n2) to (highest number) ~>
<~ set (iterator) to (n1) ~>
<~ repeat until ([iterator] = [([n2] + [1])]) ~>
    <~ add (iterator) to list (list) ~>
    <~ change (iterator) by (1) ~>
<~ close repeat ~>

Last edited by HD123 (2010-12-12 14:37:38)


~~HD123~~
Treat others as you want to be treated. |  big_smile  | http://i.imgur.com/OaNrY.gif | http://blocks.scratchr.org/libstatus.php?user=HD123&amp;online=http://lemonfanatic.webs.com/ONLINE.png&amp;offline=http://lemonfanatic.webs.com/OFFLINE.png

Offline

 

Board footer