Green Flag
Set [Random Variable] to (pick random (1) to (5) )
If < (Random Variable) = (1) >
Say (Hello!)
{End of If}
If < (Random Variable) = (2) >
Say (Bye!)
{End of If}
If < (Random Variable) = (3) >
Say (A random statement!)
{End of If}
If < (Random Variable) = (4) >
Say (Ok!)
{End of If}
If < (Random Variable) = (5) >
Say (Nothing!)
{End of If}
=
[blocks]
<when green flag clicked>
<set{ Random Variable }to( <pick random( 1 )to( 5 )) )>
<if><( <{ Random Variable }> <=> 1 )>
<say[ Hello! ]
<end>
<if><( <{ Random Variable }> <=> 2 )>
<say[ Bye! ]
<end>
<if><( <{ Random Variable }> <=> 3 )>
<say[ A random statement! ]
<end>
<if><( <{ Random Variable }> <=> 4 )>
<say[ Ok! ]
<end>
<if><( <{ Random Variable }> <=> 5 )>
<say[ Nothing! ]
<end>
[/blocks]
Last edited by laptop97 (2011-10-30 19:16:35)
Offline
I don't know, but I'd guess it uses the clock and runs it through a random number algorithm. For example, the milliseconds on the computer's clock says 76. The computer runs it through a formula (for example: (2x+4)%10) to get 6.
Offline
Here is the scratch code for it:
randomFrom: t1 to: t2
| t3 t4 t5 |
t3 _ t1 min: t2.
t4 _ t1 max: t2.
t5 _ RandomGen next * (t4 - t3) + t3.
t3 isInteger & t4 isInteger
ifTrue: [t5 _ (RandomGen next * (t4 + 1 - t3)) truncated + t3]
ifFalse: [t5 _ RandomGen next * (t4 - t3) + t3].
^ t5
~AIOlover~
Offline
AIOlover wrote:
Here is the scratch code for it:
randomFrom: t1 to: t2
| t3 t4 t5 |
t3 _ t1 min: t2.
t4 _ t1 max: t2.
t5 _ RandomGen next * (t4 - t3) + t3.
t3 isInteger & t4 isInteger
ifTrue: [t5 _ (RandomGen next * (t4 + 1 - t3)) truncated + t3]
ifFalse: [t5 _ RandomGen next * (t4 - t3) + t3].
^ t5
this is only block method.
look at kernel-numbers/random
Offline
Like this:
342.972465978243675978236459872346635758964258962490
And which numbers depend on what the limits of the random number are.
Offline