GameSalad

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

help generating completely random numbers

giacomopoppigiacomopoppi Posts: 914Member, PRO
edited December 2011 in Working with GS (Mac)
Hello everyone, it's been a while since I posted on the forums.
I am having some difficulties with a simple, but unresolvable issue. My game needs to generate constantly random numbers between 1 and 3. This may sound easy but when I try to use the normal method:

every 5 seconds
random(1,3)

I get about 90% of ones and twos (for example), and only a 10% of threes. This is surely not random.

Does anyone have an idea for a work around? maybe using game.time to generate a random number?

Thanks in advance
Giacomo

Comments

  • RThurmanRThurman Posts: 2,824Member, Sous Chef, PRO
    I just performed the same test (except I made it faster than every 5 seconds) and got 36% ones, 32% twos, and 32% threes.
  • giacomopoppigiacomopoppi Posts: 914Member, PRO
    Ok, ill reexplain the scenario to make it more clear and see if what i am doing is wrong.
    I have a car (the actor) which I spawn 7 times in the scene which I then recycle when they go off screen. There are three colours for the cars: one green, one red and one yellow.
    I need to assign each car a colour randomly. To do this I do:

    change attribute: self.carimage to random (1,3)

    when self.carimage is = 1
    change image....

    when self.carimage is = 2 ...etc

    I also say this when I recycle the car:
    when car is off screen:
    change attribute: self.carimage to random (1,3)

    Every time I play the game I get 3 cars one colour, 3 cars another and 1 car for the last colour.

    :/

    understand?
  • giacomopoppigiacomopoppi Posts: 914Member, PRO
    Perfect, I saw that before but I didn't think it applied in my case. I just saw the video and I think it might work. ;)
    Thanks guys ;)

    Giacomo
  • The_Gamesalad_GuruThe_Gamesalad_Guru Posts: 9,913Member
    edited December 2011
    You can always modify what he does in the video. For example, creating say a health bar is the same technique one might use to make a laser and such... Most of the techniques demonstrated in the videos can be modified or ported to other tasks, don't get locked in on the specific example or you'll miss the forest for the trees.
  • giacomopoppigiacomopoppi Posts: 914Member, PRO
    Yes, I think I might have to. It's a shame though... not being able to release a game because I can't change the image of a couple of actors...
    Tshirt, will it be quite self-explanitory once tables arrive? (thanks!)

    Giacomo
  • The_Gamesalad_GuruThe_Gamesalad_Guru Posts: 9,913Member
    @TshirtBooth You are the greatest! If you ever come to Cape Cod look me up I owe you a lobster dinner for all you taught me.
This discussion has been closed.