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

#1 2010-09-18 16:29:23

Wh00z
New Scratcher
Registered: 2010-09-17
Posts: 3

Random Number but NOT 2 latest random

Hi there. Started using scratch eariler today and now i stumbeled opon a probelm. I need to use "Pick random 1 - 10" but i need to get a random number thats NOT one of the 2 latest pick random numbers. Got it to work with latest but now i cant seem to get it to the 2nd latest. Anyone got any idea on how to fix this?

Offline

 

#2 2010-09-18 16:32:10

soupoftomato
Scratcher
Registered: 2009-07-18
Posts: 1000+

Re: Random Number but NOT 2 latest random

<when green flag clicked>
<repeat( <set{  }to( <pick random(  )to(
[add __ to Latest Numbers}
<end>
<change{  }by(
<if>Latest numbers contains ___
<set{  }to(
<else>

<end>


I'm glad to think that the community will always be kind and helpful, the language will always be a fun and easy way to be introduced into programming, the motto will always be: Imagine, Program, Share - Nomolos

Offline

 

#3 2010-09-18 16:36:05

Harakou
Community Moderator
Registered: 2009-10-11
Posts: 1000+

Re: Random Number but NOT 2 latest random

You could have two variables ("previous" and "second previous", or whatever you want) and use a repeat until loop to repeatedly choose a random number until it equals neither of them. Then "bump" them down like this:

Code:

Repeat until not< <choice = previous> or <choice = second_previous> >
    set choice to pick random 1 to 10
EndRepeat
set second_previous to previous
set previous to choice

If that makes sense, great.  big_smile  If it doesn't, I can blockify it for you.


http://www.blocks.scratchr.org/API.php?action=random&amp;return=image&amp;link1=http://i.imgur.com/OZn2RD3.png&amp;link2=http://i.imgur.com/duzaGTB.png&amp;link3=http://i.imgur.com/CrDGvvZ.png&amp;link4=http://i.imgur.com/POEpQyZ.png&amp;link5=http://i.imgur.com/ZKJF8ac.png

Offline

 

#4 2010-09-18 17:09:46

Wh00z
New Scratcher
Registered: 2010-09-17
Posts: 3

Re: Random Number but NOT 2 latest random

It made sense  smile  Thanks alot both of you

Offline

 

Board footer