N
Nathan Archer
Guest
I have a problem with the random number generator only working some of the time and I can't understand why.
Background: I have an algorithm that generates a bunch of building objects which also generates window objects for each building. So it looks like this:
When you click the switch on the left, the algorithm illuminates the dark windows randomly, with a 1/20 chance every step.
This works as intended the first time if the obj_window creation code looks like this (assigning a random value so 1/3 of the lights are already turned on):
Upon entering the room the second time (after each room does a little visual thing, they choose a random room), flipping the switch doesn't appear to work at first, but then you see the two buildings in the upper right hand corner (I presume the ones generated last) have windows that light up very slowly and only for the buildings in the upper right hand corner. After about a minute a dozen or so lights turn on. When it works correctly they turn on in about a second.
This also happens when entering the room the first time if the creation code looks like this (lights turned off by default):
I'm hoping someone with more insight as to how the Game Maker RNG engine works because I have no idea why it will only work correctly some of the time and work DIFFERENTLY/SLOWLY the rest of the time.
Note: The lights don't come on starting in the upper right hand corner when it's working correctly, they all just come on randomly. I don't know why Game Maker is choosing the upper right hand corner.
Background: I have an algorithm that generates a bunch of building objects which also generates window objects for each building. So it looks like this:
When you click the switch on the left, the algorithm illuminates the dark windows randomly, with a 1/20 chance every step.
Code:
//obj_lightswitch
if(on){
with(obj_window_light){
if(irandom(20) == 1){
on = true;
if(obj_window_light.on == false){
//show_debug_message("There are unactivated lights")
exit
}else{
end_level();
}
}
}
}
This works as intended the first time if the obj_window creation code looks like this (assigning a random value so 1/3 of the lights are already turned on):
Code:
on = choose(false, true, false)
//on = false;
my_scale = 1
This also happens when entering the room the first time if the creation code looks like this (lights turned off by default):
Code:
//on = choose(false, true, false)
on = false;
my_scale = 1
I'm hoping someone with more insight as to how the Game Maker RNG engine works because I have no idea why it will only work correctly some of the time and work DIFFERENTLY/SLOWLY the rest of the time.
Note: The lights don't come on starting in the upper right hand corner when it's working correctly, they all just come on randomly. I don't know why Game Maker is choosing the upper right hand corner.