Random not Randoming well enough

0 favourites
  • 8 posts
From the Asset Store
2D fighting template based in the game that defined the fighting games genre.
  • Hi Guys,

    I have this issue with the "random" expression. So I have some bombs and powerups spawning at the top of the screen and moving down (as if the player is moving and the mines are static).

    In my event sheet I have:

    "Every Random(35, 70) seconds ---

    Time > 60 seconds             --- Create powerupONE"

    and then in the separate condition

    "Every Random(35, 70) seconds ---

    Time > 75 seconds             --- Create powerupTWO"

    How I understand it, it should work in the following way:

    Once the time is more than 75, let's say 100, and once the condition gets checked, the engine chooses a random number between 35 and 70, let's say 41. So after 41 seconds it will create powerupONE, then it checks the next condition, Chooses a random number between 35 and 70, lets say 63, and creates powerupTWO in 63 seconds.

    What in reality happens is that these two powerups show up very very close to each other, as if the random doesn't really random so well. Like I have an impression that once the first condition picks a number, the second one picks a number by +3/-3 seconds, no more. Like they're randoming almost the same number because the powerups show up almost on the same level, when in theory, there is a whole 35 seconds space to choose from, the engine seems to choose almost the same number most of the time..

    At first I thought i'm tripping but I'm not.

    Does anyone have an idea how exactly does construct 2 random? Or what can be the problem here?

    Thanks in advance

  • Using every random second is not the ideal way to do things.

    You would be better off comparing a random number to a set number, and if they are equal, then do something.

  • So like:

    "Every 1 second --- random(1, 10)

    ___if X = 5    --- Spawn powerupONE"

    ?

    Could you also please explain why is "every random seconds" not the best way to go around, and how does it work in general (what might be causing the problems i'm having)

  • Just do a system compare, no need for every xx seconds.

    The reason you shouldn't use random is because the system doesn't remember what the random value was tick to tick.

    Also random uses decimals so use int, or abs, etc, otherwise it may never be equal.

  • yeah, I know about random using decimals, but I figured when I use it on seconds it doesn't matter since even if the system spawn smth 33.728 seconds, it'd be fine by me, but in the equality case, it makes sense of course.

    hmm.. so could you explain how the algorithm above would be executed? just curious to know more about the engine.

    As I said, I imagined "every random(1, 10) seconds" working the following way:

    The system checks the condition, chooses 3.456, executes the action after 3.456 seconds. Then it checks the condition again (as you mentioned it won't remember that it chose 3.456 before, but it should still random nonetheless right?) and chooses 7.219, after 7.219 seconds it executes the action and checks the condition again. etc.

    If what you meant was that, when it checks the condition and chooses 5.15 for example, and then before that time passes forgets this choice the next tick, then it wouldn't spawn anything at all, however that's not the case.

    Sorry for writing so much, I just wanna get to the bottom of this :D

    P.S. I understand your solution, but what if what I want specifically is for object to spawn the least 2 seconds apart and the most 7 seconds apart and it should random in between? Like I want to progressively narrow this gap, imagine something like:

    __________________________________________________

    LOW LIM = 2

    HIGH LIM = 10

    Every 1 second --- substract 0.1 from LOW LIM

                              --- substract 0.8 from HIGH LIM

    Every random(LOW LIM, HIGH LIM) --- spawn object

    __________________________________________________

    how do I achieve this if "every random x second" doesn't work that way?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • https://dl.dropboxusercontent.com/u/666516/rolltimerexample.capx

    I made an example that should show what to expect.

    Notice how object with the value 90 are created much less often.

    Im not sure what happens in the system when doing every random seconds, might have to ask Ashley about that.

  • I checked out your file (i'm working on 126 though) and I see what you mean but I don't think that'd work in my case.

    Is there a way to tag the user you mentioned here somehow so I can get some more info?

    Thanks for the support btw!

  • I've just tried the following:

    Every TEMP seconds --- spawn object

                                       --- set TEMP to random(1, 7) seconds

    and this seems to be working as it should..

    although if someone who knows what happens in the engine finds this topic, I would appreciate an explanation of how these algorithms work and what's the difference : )

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)