Random?

Archive of the old editing forum
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.
User avatar
LilWhiteMouse
Posts: 2270
Joined: Tue Jul 15, 2003 7:00 pm
Location: Maine, US
Contact:

Random?

Post by LilWhiteMouse »

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?
User avatar
bagheadspidey
Posts: 1490
Joined: Sat Oct 20, 2007 10:31 pm
Contact:

Re: Random?

Post by bagheadspidey »

How does ZDoom pick random numbers?
Not very carefully.

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.
User avatar
LilWhiteMouse
Posts: 2270
Joined: Tue Jul 15, 2003 7:00 pm
Location: Maine, US
Contact:

Re: Random?

Post by LilWhiteMouse »

bagheadspidey wrote:So does putting in delays if you can afford to do that.
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.
User avatar
HotWax
Posts: 10002
Joined: Fri Jul 18, 2003 6:18 pm
Location: Idaho Falls, ID

Re: Random?

Post by HotWax »

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.
This shouldn't work as well as you'd expect because of the way Doom generates "random" numbers.

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. :)
User avatar
LilWhiteMouse
Posts: 2270
Joined: Tue Jul 15, 2003 7:00 pm
Location: Maine, US
Contact:

Re: Random?

Post by LilWhiteMouse »

HotWax wrote:Doom however doesn't have the luxury of being able to seed the RNG, otherwise demos wouldn't work at all.
I always assumed that demos recorded the seed used to maintain consistency.
User avatar
HotWax
Posts: 10002
Joined: Fri Jul 18, 2003 6:18 pm
Location: Idaho Falls, ID

Re: Random?

Post by HotWax »

LilWhiteMouse wrote:I always assumed that demos recorded the seed used to maintain consistency.
If it is recorded, I can't find it here.
User avatar
LilWhiteMouse
Posts: 2270
Joined: Tue Jul 15, 2003 7:00 pm
Location: Maine, US
Contact:

Re: Random?

Post by LilWhiteMouse »

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.
User avatar
Cutmanmike
Posts: 11354
Joined: Mon Oct 06, 2003 3:41 pm
Operating System Version (Optional): Windows 10
Location: United Kingdom
Contact:

Re: Random?

Post by Cutmanmike »

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.
User avatar
Nash
 
 
Posts: 17503
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: Random?

Post by Nash »

"Well, maybe the ghost was murdered in the dining room, so that's why it appears there a lot".

:P
User avatar
randi
Site Admin
Posts: 7749
Joined: Wed Jul 09, 2003 10:30 pm
Contact:

Re: Random?

Post by randi »

LilWhiteMouse wrote:How does ZDoom pick random numbers?
It uses the same random number algorithm that Lee Killough added to BOOM.
HotWax wrote:Doom however doesn't have the luxury of being able to seed the RNG, otherwise demos wouldn't work at all.
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.
LilWhiteMouse wrote:I always assumed that demos recorded the seed used to maintain consistency.
They do.
HotWax wrote:If it is recorded, I can't find it here.
Those have nothing to do with ZDoom's demo format.
User avatar
randi
Site Admin
Posts: 7749
Joined: Wed Jul 09, 2003 10:30 pm
Contact:

Re: Random?

Post by randi »

randy wrote:The game is supposed to be seeding the RNG on startup from the system clock.
And as far as I can tell, it still is. (And is additionally changed each time you start a new non-network game.)
User avatar
LilWhiteMouse
Posts: 2270
Joined: Tue Jul 15, 2003 7:00 pm
Location: Maine, US
Contact:

Re: Random?

Post by LilWhiteMouse »

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.)
::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.
User avatar
randi
Site Admin
Posts: 7749
Joined: Wed Jul 09, 2003 10:30 pm
Contact:

Re: Random?

Post by randi »

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.
User avatar
Rachael
Posts: 13965
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her
Contact:

Re: Random?

Post by Rachael »

Did you get tired of the name randy?
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49252
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Random?

Post by Graf Zahl »

Locked

Return to “Editing (Archive)”