Fast floating-point random numbers
Here's a very fast way of generating FP random numbers in [0.0, 1.0) based on the XORShift PRNG:
Code:
move.l state, d0 |
now this i can really use! i have something similar in my own code, but it was a bit of a bodge and randomness isn't very good. will try this instead at earliest opportunity. (but keep my current one in the sound effects generation so it doesn't change the sound!!)
|
Quote:
|
Pretty much any PRNG will work fine.. the main idea here was just to construct the number in a faster way than by using division or multiplication, it doesn't matter where the random bits come from really.
|
i used a simple LCG to generate the restart codes from world map co-ordinates, that should be pretty good for randomness but doesn't need to be fast.
my in-game random used rotates and xor iirc, randomness however was not very good, resulting often in enemies firing shots in bursts for some reason |
Quote:
Quote:
Xorgens is for when you need something really good with a large period. |
Quote:
also, needs to be perfectly reversible. LCG is easy to implement and easy to invert. that was why i used it. i will read the Xorgens paper though! |
The best randomness is achieved when you use several RNG and mix their results together.
LCG has problems with the lower bits of the output ; xorshift has problems with seeds containing many '0'. But if you mix both together you'll get very good results, especially if you also mix that with values read from hardware counters (like cia timers). So you can just keep your LCG for level code generation and use a more sophisticated RNG for the game itself. |
hey LCG could even stand for "Level Code Generation", well fancy that
something occurred to me, which is that i'm not typically using loads of random numbers per frame, so i could just generate a stack of them in advance to use when needed, replenishing it whenever there's spare time, then performance wouldn't be so much of an issue. |
Xorgens4096 + Sha 1 or Sha 256 for seeding.
|
are we going for cryptographic level strength now?
|
A little bit overkill for a game indeed.
|
Quote:
|
i did see a talk about tool-assisted speed runs at EMFcamp that explained how people sort of cheat the game by exploiting the random number sequence and it did set me wondering about techniques to thwart this sort of thing. Using, for instance, beam position XOR onto the State value might make things a little harder to predict. At least on real hardware... or might make it highly dependent on exactly which emulator is being used!
|
Quote:
Code:
move.l seed,d0 |
Quote:
Quote:
I use this to generate data to be used by an external mixer: Code:
; |
Isn't just reading $dff006 enough for most game purposes?
|
Quote:
If you want to do that huge test, then just do it :D (However be awared that the tests fill fail if you extract megabytes of rnd data per second on an emulator). Quote:
|
Quote:
Quote:
Quote:
Quote:
|
Quote:
|
All times are GMT +2. The time now is 05:48. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.