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

Random()

Post by LilWhiteMouse »

Are there any tricks to generating a more random number? Chibi Rebellion's hub is randomly selected via an OPEN script in the first map, but it tends to select the same maps for the first session. Other random() uses have similar repetitious results. For example, the first time the Armorery map is loaded, the access code is almost always 2-2. Kinda takes the spontaneity out of the mod, which was a major point of making it.
User avatar
Xaser
 
 
Posts: 10773
Joined: Sun Jul 20, 2003 12:15 pm

Post by Xaser »

My gosh! That thing is random enough already. :? At the rate i'm going, It'll take me forever just to see all the levels!!!

P.S: Even in the face of the concussion blaster (ring shooter), i keep using the darn blaster pistol. I'm a nut at conserving ammo (Mainly because I suck with fists and Chainsaw :roll: ).

[FUTURE-EDIT] Pssshh, chainsaw kicks ass. I don't have a clue what past-me is talking about.
Last edited by Xaser on Sat Feb 20, 2010 2:22 pm, edited 1 time in total.
User avatar
randomlag
Posts: 405
Joined: Thu Jul 17, 2003 10:10 pm

Re: Random()

Post by randomlag »

LilWhiteMouse wrote:Are there any tricks to generating a more random number?
Yes. I've not experimented with ACS nor looked at the actual implementation in ZDOOM (could be everything is fine - since random does repeat after all). Common trick are to set the "seed" variable and to vary the actual range (vs constants).

You might try a double random - the 1st one drives the 2nd ones range. You can also look for other variable events as the game is played to vary the "random constants" to get more unpredictable results.

I bet you can think of many others :idea:
User avatar
randi
Site Admin
Posts: 7749
Joined: Wed Jul 09, 2003 10:30 pm

Post by randi »

The random number generator gets seeded by the system clock when you start. The algorithm is essentially the same one Lee Killough used in BOOM. I have no idea how random it really is. You could do a test run of print (d:random())s to see what kind of numbers it's generating and devise an algorithm to produce results more to your liking.
User avatar
Hirogen2
Posts: 2033
Joined: Sat Jul 19, 2003 6:15 am
Operating System Version (Optional): Tumbleweed x64
Graphics Processor: Intel with Vulkan/Metal Support
Location: Central Germany

Post by Hirogen2 »

The least randomness an application should have is time(NULL) ^ getpid(). perlfunc(1) even propes "time ^ ($$ + ($$ << 15))".
User avatar
Sphagne
Posts: 513
Joined: Wed Jul 16, 2003 3:36 am

Post by Sphagne »

What is selected for the initial Random Seed, Maybe main computer clock ticks would be a good choice.
Cyb
Posts: 912
Joined: Tue Jul 15, 2003 5:12 pm

Post by Cyb »

Sphagne wrote:What is selected for the initial Random Seed, Maybe main computer clock ticks would be a good choice.
randy wrote:The random number generator gets seeded by the system clock when you start.
User avatar
randi
Site Admin
Posts: 7749
Joined: Wed Jul 09, 2003 10:30 pm

Post by randi »

Specifically, the seed is the result of the time() function, which is the number of seconds since midnight, January 1, 1970. Not as random as XORing with the process ID, but still much more random than Doom was. It had a table of 256 random numbers it looped through, and it always started at the first entry, so each run of the game always produced the same random numbers.
User avatar
Hirogen2
Posts: 2033
Joined: Sat Jul 19, 2003 6:15 am
Operating System Version (Optional): Tumbleweed x64
Graphics Processor: Intel with Vulkan/Metal Support
Location: Central Germany

Post by Hirogen2 »

randy wrote:It had a table of 256 random numbers it looped through, and it always started at the first entry, so each run of the game always produced the same random numbers.
Which was necessary so monsters in a demo LMP would run the same way they did when recording.
Fredrik
Posts: 66
Joined: Tue Jul 15, 2003 4:05 pm

Post by Fredrik »

Hirogen2 wrote:
randy wrote:It had a table of 256 random numbers it looped through, and it always started at the first entry, so each run of the game always produced the same random numbers.
Which was necessary so monsters in a demo LMP would run the same way they did when recording.
It wasn't necessary, you could just store the initial seed in the header of the demo file.
User avatar
Hirogen2
Posts: 2033
Joined: Sat Jul 19, 2003 6:15 am
Operating System Version (Optional): Tumbleweed x64
Graphics Processor: Intel with Vulkan/Metal Support
Location: Central Germany

Post by Hirogen2 »

Fredrik wrote:It wasn't necessary, you could just store the initial seed in the header of the demo file.
But there is no seed in the Doom demo lump! :D
User avatar
HotWax
Posts: 10002
Joined: Fri Jul 18, 2003 6:18 pm
Location: Idaho Falls, ID

Re: Random()

Post by HotWax »

LilWhiteMouse wrote:Are there any tricks to generating a more random number? Chibi Rebellion's hub is randomly selected via an OPEN script in the first map, but it tends to select the same maps for the first session. Other random() uses have similar repetitious results. For example, the first time the Armorery map is loaded, the access code is almost always 2-2. Kinda takes the spontaneity out of the mod, which was a major point of making it.
If possible, base the random numbers of things that the player does. People are alot more random than computers.
User avatar
wildweasel
Posts: 21706
Joined: Tue Jul 15, 2003 7:33 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): A lot of them
Graphics Processor: Not Listed

Post by wildweasel »

Going into more detail from HotWax's post:

Have certain actions (switches, enemies, pickups, etc) set flags. When something that needs to be random comes up, read those flags and add them together (like DMFLAGS, or such similar cvars). Then perform whatever calculations you need for your stuff (like next map, security code, whatever), and poof.
User avatar
David Ferstat
Posts: 1113
Joined: Wed Jul 16, 2003 8:53 am
Location: Perth, Western Australia

Post by David Ferstat »

wildweasel wrote:Going into more detail from HotWax's post:

Have certain actions (switches, enemies, pickups, etc) set flags. When something that needs to be random comes up, read those flags and add them together (like DMFLAGS, or such similar cvars). Then perform whatever calculations you need for your stuff (like next map, security code, whatever), and poof.
Perhaps what you should do is base your random numbers on the TIME that the player does things. That's guaranteed to be random. There's just no way the player could perform even a small sequence of events with EXACTLY the same timing twice in a row. No matter how hard the player tries, human reaction time is sufficiently long and variable for a computer to register the differences.
User avatar
Hirogen2
Posts: 2033
Joined: Sat Jul 19, 2003 6:15 am
Operating System Version (Optional): Tumbleweed x64
Graphics Processor: Intel with Vulkan/Metal Support
Location: Central Germany

Post by Hirogen2 »

>>Have certain actions (switches, enemies, pickups, etc) set flags. When something that needs to be random comes up, read those flags and add them together (like DMFLAGS, or such similar cvars). Then perform whatever calculations you need for your stuff (like next map, security code, whatever), and poof.

No /dev/random for Windows :)

>Perhaps what you should do is base your random numbers on the TIME that the player ...
Extremely cool idea. Heh, hard to do the action in 1/35 seconds.

Return to “Editing (Archive)”