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

#1 2012-12-10 02:10:19

Aditya007
Scratcher
Registered: 2012-11-27
Posts: 63

Pick Random

I wish if there would be a command in which you give 2 numbers and it randomly picks one.
I know there is  (Pick Random ___ to ___).
But it should be (Pick Random ___ or ___).


Wolf_OS!!!  smile  Check My Stuff  tongue  Need Help?  Currently, I am http://blocks.scratchr.org/API.php?user=Aditya007&action=onlineStatus&type=square
http://i49.tinypic.com/15gy1j6.jpg

Offline

 

#2 2012-12-10 12:00:45

Prestige
Scratcher
Registered: 2008-12-15
Posts: 100+

Re: Pick Random

You can do this:

add [number 1] to [numbers v]
add [number 2] to [numbers v]
set [random v] to (pick random [1] to [2])
if <(random) = [1]>
set [random v] to (item [1 v] of [numbers v])
else
set [random v] to (item [2 v] of [numbers v])

Last edited by Prestige (2012-12-10 12:01:23)


"Don't insult someone until you've walked a mile in their shoes. That way, if they don't like what you have to say, you'll be a mile away and still have their shoes  smile  "

Offline

 

#3 2012-12-10 16:19:30

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Pick Random

Prestige wrote:

You can do this:

add [number 1] to [numbers v]
add [number 2] to [numbers v]
set [random v] to (item (pick random (1) to (2)) of [numbers v])

Simplified.

Edit: Simplified even more.

Last edited by ErnieParke (2012-12-10 16:29:36)


http://i46.tinypic.com/35ismmc.png

Offline

 

Board footer