Random 5 numbers...

sebmacflysebmacfly Member Posts: 1,018
edited November -1 in Working with GS (Mac)
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

Comments

  • victorkin11victorkin11 Member Posts: 251
    a=random (5,100)
    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
  • synthesissynthesis Member Posts: 1,693
    (DEFAULT INTEGERS)
    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)
  • sebmacflysebmacfly Member Posts: 1,018
    Thanks Synthesis, i think that's a good way...
    I'll try that!

    Have you ever used these rules?
  • sebmacflysebmacfly Member Posts: 1,018
    @Synthesis :

    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
  • sebmacflysebmacfly Member Posts: 1,018
    So crazy, i can't make it... Any help please?
  • jstrahanjstrahan Member Posts: 498
    in synthesis example did u make sure to change the rules to check for any condition instead of all conditions
  • synthesissynthesis Member Posts: 1,693
    This is part of my frustration with GS (or my failure to understand its code hierarchy). It should work as you have it....but it appears the rules aren't re-firing a second time if necessary.

    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.
  • sebmacflysebmacfly Member Posts: 1,018
    jstrahan said:
    in synthesis example did u make sure to change the rules to check for any condition instead of all conditions

    Same.... thx
  • sebmacflysebmacfly Member Posts: 1,018
    synthesis said:
    This is part of my frustration with GS (or my failure to understand its code hierarchy). It should work as you have it....but it appears the rules aren't re-firing a second time if necessary.

    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.

    That's a little hard to understand... I'm trying, i will let you know
    Thank you sir
  • synthesissynthesis Member Posts: 1,693
    The above routine does 3 things...
    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.
  • sebmacflysebmacfly Member Posts: 1,018
    Hummm.... i can't set a defaut attribute to random(0,100) (in the Game, Attributes)
  • synthesissynthesis Member Posts: 1,693
    The defaults in the attribute are still 0...
    the first 5 behaviors in the actor should be change attribute behaviors changing them from 0 to random(0,100).
  • sebmacflysebmacfly Member Posts: 1,018
    OMG... I can't make it work....
  • synthesissynthesis Member Posts: 1,693
    I built a demo...but GS isn't letting me upload at the moment. Maybe I'll get it up later.

    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.
  • victorkin11victorkin11 Member Posts: 251
    Ha! I don't know tshirtbooth have a good demo!

    anyway, here is my demo.

    http://gamesalad.com/game/play/80029

    range from 0 to 100
  • synthesissynthesis Member Posts: 1,693
    I had a demo too...but for some darn reason...GS will not connect to the server to publish it.

    Viktorin's though looks to be good to go! Seems like it will work well for you.

    Over and out!
  • sebmacflysebmacfly Member Posts: 1,018
    Thanks guys, i'll take a look ;)

    @victorkin11 :
    I can't download your project file... ?
  • victorkin11victorkin11 Member Posts: 251
    ok! I fix it!
  • sebmacflysebmacfly Member Posts: 1,018
    Thanks a lot to all of you guys!

    This topic is [Solved] :)

    Have a good day all
Sign In or Register to comment.