Random 5 numbers...
sebmacfly
Member Posts: 1,018
Hi there
Somebody can help me please?
I need to random 5 number (from 0 to 100) but WITHOUT 2 same numbers...
Exemple
5-9-45-12-7 OK
5-5-3-12-99 Not OK...
Thanks to all and have a good day...
Cheers
Somebody can help me please?
I need to random 5 number (from 0 to 100) but WITHOUT 2 same numbers...
Exemple
5-9-45-12-7 OK
5-5-3-12-99 Not OK...
Thanks to all and have a good day...
Cheers
Comments
b=random(4,a-1)
c=random(3,b-1)
d=random(2,c-1)
e=random(1,d-1)
101>a>b>c>d>e>0
a = 0
b = 0
c = 0
d = 0
e = 0
(ACTOR BEHAVIORS)
a = random(0,100)
b = random(0,100)
Rule B Test:
when b=a
...b = random(0,100)
otherwise
c = random(0,100)
Rule C Test:
when c=a or c=b
...c = random(0,100)
otherwise
d = random(0,100)
Rule D Test:
when d=a or d=b or d=c
...d = random(0,100)
otherwise
e = random(0,100)
Rule E Test:
when e=a or e=b or e=c or e=d
...e = random(0,100)
I'll try that!
Have you ever used these rules?
Don't Work... i'm missing something?
Sometimes 2 or 3 same numbers... and sometimes 0...
(i use 5 to make sure that the rules are working good... but i will make it 1 to 100)
See the picture :
http://macfly57.free.fr/GSRandom1to5.jpg
It sounds like you need to create a loop wrapper for each test.
something like this:
(DEFAULT ATTRIBUTES)
a = random(0,100)
b = random(0,100)
c = random(0,100)
d = random(0,100)
e = random(0,100)
checkValues=true
(ACTOR BEHAVIORS)
RULE X WRAPPER START:
when checkValues = true
[ the behaviors and rules below are inside the Rule X wrapper ]
resetB = false
resetC = false
resetD = false
resetE = false
Rule B Test:
when b=a
...resetB = true
...checkValues = false
Rule C Test:
when c=a or c=b
...resetC = true
...checkValues = false
Rule D Test:
when d=a or d=b or d=c
...resetD = true
...checkValues = false
Rule E Test:
when e=a or e=b or e=c or e=d
...resetE = true
...checkValues = false
checkValues = false
[ end of RULE X WRAPPER ]
[ separate RULES below to execute when needed from above ]
When resetB = true
b = random(0,100)
...checkValues = true
When resetC = true
c = random(0,100)
...checkValues = true
When resetD = true
d = random(0,100)
...checkValues = true
When resetE = true
d = random(0,100)
...checkValues = true
If this doesn't work...maybe try tweaking things...as the logic seems sound.
Maybe someone else has a more elegant idea on how to do that sequence.
Thank you sir
first...it defines a number for each of the 5 slots.
Then it defaults the check loop to true.
second...
It runs the check loop. There it sets a default (for future loops) for each number slot to reset to false. Then it checks the B digit for a match. If matched...it switches the resetB value to true to grab a new random number and then shuts off the loop. If B is okay...it skips it and goes to the C test...and so on...looking for a matching digit.
third...
Now that the resetB value is true (or any other reset switch for that matter)...it goes down the hierarchy and grabs a new B value in the "resetB" rule and then sets the check loop to true again...and then goes back to the check loop to retest.
This loop continues until all 5 digits are unique. Once they are all unique...the loop shuts off.
the first 5 behaviors in the actor should be change attribute behaviors changing them from 0 to random(0,100).
I had to put the final override switch booleans (where checkvalues = false at the end of the X wrapper) inside a timer with a .05 delay.
For some reason...it wouldn't fire in sequence correctly. With the micro delay...it works. Not sure if its a GS thing or a logic hierarchy thing.
anyway, here is my demo.
http://gamesalad.com/game/play/80029
range from 0 to 100
Viktorin's though looks to be good to go! Seems like it will work well for you.
Over and out!
@victorkin11 :
I can't download your project file... ?
This topic is [Solved]
Have a good day all