Random?
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
- LilWhiteMouse
- Posts: 2270
- Joined: Tue Jul 15, 2003 7:00 pm
- Location: Maine, US
- Contact:
Random?
How does ZDoom pick random numbers? When playing Chibi Rebellion, it has a tendency to choose the same things over and over. One of my maps places an item in a random location, but ZDoom favors two out of five mapspots. At first I just assumed it was luck, but as many times as I've played/tested these maps, a definitive pattern has emerged. In the last five play throughs, Chibi Rebellion has used two of the maps every time. Each map only had a 1:6 chance of being picked. I have a random monster spawner with two monsters in it's pool, one of them listed twice. I'll play through a number of hubs, but never have the lone monster appear out of like 12 spawns. A coincidence is a coincidence is a coincidence. Is it just my computer?
- bagheadspidey
- Posts: 1490
- Joined: Sat Oct 20, 2007 10:31 pm
- Contact:
Re: Random?
Not very carefully.How does ZDoom pick random numbers?
I've tried giving the random numbers more entropy by "priming" the rng by having it generate a bunch of junk random numbers in a loop and then breaking from the loop randomly; it seems to kind of work. So does putting in delays if you can afford to do that.
- LilWhiteMouse
- Posts: 2270
- Joined: Tue Jul 15, 2003 7:00 pm
- Location: Maine, US
- Contact:
Re: Random?
I'm using three "delay (random (1, 3));" at the beginning of the map selection script already. Didn't know if maybe the timer played an influence on random(). In Quick Basic, I'd use RANDOMIZE TIMER to tell it to pick a new random number pool based on the computer's clock. That seemed to work well enough.bagheadspidey wrote:So does putting in delays if you can afford to do that.
Re: Random?
This shouldn't work as well as you'd expect because of the way Doom generates "random" numbers.bagheadspidey wrote:I've tried giving the random numbers more entropy by "priming" the rng by having it generate a bunch of junk random numbers in a loop and then breaking from the loop randomly; it seems to kind of work. So does putting in delays if you can afford to do that.
In truth, no computer is capable of generating truly random numbers, which is why you have to "seed" the RNG using the clock. This works well enough because the clock is constantly changing. Given an application that behaves 100% the same every time, at least the time it's being run should be different so random number generation should pick different values.
Doom however doesn't have the luxury of being able to seed the RNG, otherwise demos wouldn't work at all. If you were to play the same map with the same settings and execute the exact same inputs twice in a row, you should get exactly the same result -- in fact that's what a demo playback does. Given that, if you had an OPEN script that generated 5 random numbers within the first tic, they should be the same numbers every time, notwithstanding minor differences due to map load time or whatever.
What I'd suggest would be not to pick this kind of stuff on map load. Do it when the player enters the area, or after a set amount of time. You could even use the player's current location, facing and pitch to influence the number being generated; since computers are incapable of being random, your best bet is to base your picks on the most random thing at your disposal -- the human operating it.
- LilWhiteMouse
- Posts: 2270
- Joined: Tue Jul 15, 2003 7:00 pm
- Location: Maine, US
- Contact:
Re: Random?
I always assumed that demos recorded the seed used to maintain consistency.HotWax wrote:Doom however doesn't have the luxury of being able to seed the RNG, otherwise demos wouldn't work at all.
Re: Random?
If it is recorded, I can't find it here.LilWhiteMouse wrote:I always assumed that demos recorded the seed used to maintain consistency.
- LilWhiteMouse
- Posts: 2270
- Joined: Tue Jul 15, 2003 7:00 pm
- Location: Maine, US
- Contact:
Re: Random?
This information has really thrown a wrench into my works. I setup up some test scripts, and ZDoom is seemingly flawless in repeating itself based on Timer() tics. The only reason Chibi Rebellion had the illusion of random'ness was how long it took the player to hit use. Given my habit of just hitting use when the game starts to get things going, explains why I was getting the same hubs over and over.
- Cutmanmike
- Posts: 11354
- Joined: Mon Oct 06, 2003 3:41 pm
- Operating System Version (Optional): Windows 10
- Location: United Kingdom
- Contact:
Re: Random?
This pretty much confirms something similar in one of my maps. Essentially an actor spawns randomly between 1 to about 20 spots in a huge mansion randomly between 1 minute and 10 minutes, flashes up and then vanishes. The idea was to just creep my friend out on coop, so he'd see this weird ghostly figure pop up now and again, and when he came to tell me I'd play dumb and be all "yeaah whatever".
Anyway once he'd figured the gag out, we noticed that it seemed to spawn in the dining room a lot. I said it was pure luck but my friend argued against it until I showed him the script, but we were still pretty convinced that this ghost "liked" the dining room for some odd reason.
Anyway once he'd figured the gag out, we noticed that it seemed to spawn in the dining room a lot. I said it was pure luck but my friend argued against it until I showed him the script, but we were still pretty convinced that this ghost "liked" the dining room for some odd reason.
Re: Random?
"Well, maybe the ghost was murdered in the dining room, so that's why it appears there a lot".
:P
:P
Re: Random?
It uses the same random number algorithm that Lee Killough added to BOOM.LilWhiteMouse wrote:How does ZDoom pick random numbers?
The game is supposed to be seeding the RNG on startup from the system clock. If it's not, it must have gotten broken at some point.HotWax wrote:Doom however doesn't have the luxury of being able to seed the RNG, otherwise demos wouldn't work at all.
They do.LilWhiteMouse wrote:I always assumed that demos recorded the seed used to maintain consistency.
Those have nothing to do with ZDoom's demo format.HotWax wrote:If it is recorded, I can't find it here.
Re: Random?
And as far as I can tell, it still is. (And is additionally changed each time you start a new non-network game.)randy wrote:The game is supposed to be seeding the RNG on startup from the system clock.
- LilWhiteMouse
- Posts: 2270
- Joined: Tue Jul 15, 2003 7:00 pm
- Location: Maine, US
- Contact:
Re: Random?
::shrugs:: With my old method of selecting maps at game start, I could consistently get the same results over and over. Whether it be starting a new game with the -warp command, or "map map01" from the console. To be honest, I'm not sure I ever actually started a new game from the main menu however.randy wrote:And as far as I can tell, it still is. (And is additionally changed each time you start a new non-network game.)
Re: Random?
Well, I just tried an open script that prints the result of random(0,255). The time-bias of the initial value after startup is very obvious. It also seems to have a tendency to produce runs of similar numbers. With a small enough range, I imagine it could be predisposed to producing duplicates from run to run.
I suppose I'll look for a better psuedo-random algorithm than a multiply and add.
I suppose I'll look for a better psuedo-random algorithm than a multiply and add.
Re: Random?
Did you get tired of the name randy?
