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.
-
- Posts: 2270
- Joined: Tue Jul 15, 2003 7:00 pm
- Location: Maine, US
Random()
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.
-
-
- Posts: 10773
- Joined: Sun Jul 20, 2003 12:15 pm
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 ).
[FUTURE-EDIT] Pssshh, chainsaw kicks ass. I don't have a clue what past-me is talking about.
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 ).
[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.
-
- Posts: 405
- Joined: Thu Jul 17, 2003 10:10 pm
Re: Random()
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).LilWhiteMouse wrote:Are there any tricks to generating a more random number?
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
-
- Site Admin
- Posts: 7749
- Joined: Wed Jul 09, 2003 10:30 pm
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.
-
- 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
-
- Posts: 513
- Joined: Wed Jul 16, 2003 3:36 am
-
- Posts: 912
- Joined: Tue Jul 15, 2003 5:12 pm
-
- Site Admin
- Posts: 7749
- Joined: Wed Jul 09, 2003 10:30 pm
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.
-
- 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
-
- Posts: 66
- Joined: Tue Jul 15, 2003 4:05 pm
It wasn't necessary, you could just store the initial seed in the header of the demo file.Hirogen2 wrote:Which was necessary so monsters in a demo LMP would run the same way they did when recording.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.
-
- 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
-
- Posts: 10002
- Joined: Fri Jul 18, 2003 6:18 pm
- Location: Idaho Falls, ID
Re: Random()
If possible, base the random numbers of things that the player does. People are alot more random than computers.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.
-
- 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
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.
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.
-
- Posts: 1113
- Joined: Wed Jul 16, 2003 8:53 am
- Location: Perth, Western Australia
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.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.
-
- 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
>>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.
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.