Is random function truly random?

ttrungttrung Member Posts: 6
edited March 2012 in Working with GS (Mac)
Hi guys,

I use an attribute with the random expression to generate a random number and, based on that number, an actor will be spawned. I have almost 100 actors yet Im surprised to see that there's an overwhelming of same actors being spawned over and over again. Is the random function truly random? I searched the forum and saw someone said it's not really random but those posts were over a year ago, I guess it's fixed now, right? How can I truly achieve randomness? Somebody please help me.

For example, I have:
Rule -> If x=1 -> Change Attribute y=random(1,100)
If y = 1 -> Spawn Actor 1
If y = 2 -> Spawn Actor 2
...
If y = 100 -> Spawn Actor 100

Yet I keep seeing an army of actor 3,5,19,20,30 (made up number, don't recall correctly the exact numbers but there are a few jackpot-winners keep being spawned over and over again despite their theoretically 1% chance) being spawned during my 30 times testing the game. Is it the function or is it my rotten luck?

Thanks a lot!

Comments

  • beefy_clyrobeefy_clyro Member Posts: 5,394
    Nope, it is not truly random, it picks a random seed and will reuse that each time. Go to gshelper.com and watch @tshirtbooth videos, I'm sure he has a video that uses table to make a truly random event.
  • ttrungttrung Member Posts: 6
    Thanks. Wow, that's totally unexpected. Now looks like my project will have to be greatly delayed =((
  • ttrungttrung Member Posts: 6
    Just a small question. So the technique of getting random number from a table is still based on the random expression of Gamesalad. Can anyone here confirm that if I follow that technique from @tshirtbooth then I will truly get a random number? I really am afraid that it's just a way to get specific numbers (i.e 2,4,6,8,10) instead of a range 1-10 but still getting the same issue with the normal random :(
  • LiquidGameworksLiquidGameworks Anchorage, AKMember, Sous Chef Posts: 956
    edited March 2012
    Why the delay? Take a look here:

    http://gshelper.com/?p=446

    Edit: Beat me to it. I'm not sure about that, sorry.
  • CloudsClouds Member Posts: 1,599
    Can anyone here confirm that if I follow that technique from @tshirtbooth then I will truly get a random number?
    A computer cannot generate a random number.
  • ttrungttrung Member Posts: 6
    @Tynan thanks, dude. now I know when the time of the machines come. We humanity will beat them with randomness. lol.
  • ttrungttrung Member Posts: 6
    Wow! That solved my problem! Thanks @tshirtbooth you rule!!!
  • CloudsClouds Member Posts: 1,599
    @Tynan thanks, dude. now I know when the time of the machines come. We humanity will beat them with randomness. lol.
    Randomness and soft fruit, from what we can work out the machines hate soft fruit, I have stocked up on nectarines for the coming war.
  • Rob2Rob2 Member Posts: 2,402
     "Hey teapots! Do you like rollerskating your hedgehog in an alarm clock hat? We do too!" 
    I have been looking in to this and as you would expect it is down to the size of your sample relative to the width of your random range. If I run random (1,10) 40 times I might see some numbers appearing say 4 times as often as others. But if I keep sampling then you will end up with a very even distribution. After a couple of thousand samples distribution is flat to within 5%. Because you are looking at a wide range (100) you wont see even distribution until you hit 10,000 plus runs of random !!

    I blame Rowntrees :)
  • CloudsClouds Member Posts: 1,599
     "Hey teapots! Do you like rollerskating your hedgehog in an alarm clock hat? We do too!" 
    I have been looking in to this and as you would expect it is down to the size of your sample relative to the width of your random range. If I run random (1,10) 40 times I might see some numbers appearing say 4 times as often as others. But if I keep sampling then you will end up with a very even distribution. After a couple of thousand samples distribution is flat to within 5%. Because you are looking at a wide range (100) you wont see even distribution until you hit 10,000 plus runs of random !!

    I blame Rowntrees :)

    I usually find that with these kinds of questions people are not actually after a random distribution (with it's clumping and repetition) - they are really after an even distribution of their sample in a vaguely non-ordered way which is often better for things like games.

    A more useful function would be one that takes your sample (let's say 5 different actors / colours / sounds / whatever) and shuffles their order within each run of 5.

    So while 'random' would look like this:

    32245 25313 41113 53142 33421 . . . . . where you can easily have a number three times in a row or 5 times within 15 numbers.

    A 'shuffle' function would look like this:

    23415 34152 23451 12354 42135 . . . . . where numbers are evenly distributed.

  • Rob2Rob2 Member Posts: 2,402
    yep... some peeps have never tossed a coin.
  • SlickZeroSlickZero Houston, TexasMember, Sous Chef Posts: 2,870
    edited March 2012
    You heard it here first, folks. GameSalad 1.0 with the long awaited Tynan Shuffle!
  • CloudsClouds Member Posts: 1,599
    You heard it here first, folks. GameSalad 1.0 with the long awaited Tynan Shuffle!
    I've had to stop the Tynan shuffle, my eyesight was being badly effected.
  • ttrungttrung Member Posts: 6
    Yeah! Shuffle is a great idea! And, to pay homage to Tynan, please Gamesalad make the Tynan Shuffle the next thing in your update!!!!!!!!!!
Sign In or Register to comment.