I will implement the old P2 LFSR, Jkiss , PCG (by Melissa O'Neill) and xoroshiro 128+. Then run the them through Testu01 and Dieharder suites. Stay tuned! (Melissa claims that her PRNG is the best available to this date. Her paper is under review as we speak)
.. and Chips P2ASM too ?
There is some mention above that was not quite xoroshiro 64b ?
@Evanh
Have you tried your zener TRNG with some RNG test suites? It would be cool to see how well it performs. I guess It would pass with Flying colors!
A challenge here would be getting rid of fixed frequency ripple in the analog domain, like Mains Hum, SMPS switching frequencies etc. There will always be some spectral sneak thru...
A challenge here would be getting rid of fixed frequency ripple in the analog domain, like Mains Hum, SMPS switching frequencies etc. There will always be some spectral sneak thru...
I think the Von Neumann algo that Chip uses in RealRandom should take care of any bias or spectral pass-thru.
@Heater
"What is the easiest way to run some decent tests on a generator?"
My way of doing it is with a tool that outputs random characters to stdout. Then you could pipe the output to a file or directly to Dieharder in raw input mode! I'm currently tryging to figure out how to run TestU01 with my tool. All "experts" says that TestU01 is a superior test battery for deciding between a "great PRNG" and a "superior PRNG". My initial testings indicates that all mentioned PRNG in this threads passes the Dieharder tests. But I have not been able to test Chips LFSR yet. Btw, I'm talking about DiehardER not Diehard as that is considered "Smile" by todays standard.
@all
I have included the C++ source code for my testing tool. It would be nice if someone with knowledge in both C++ and Verilog could help me implement Chips LFSR, so we could use that as a reference for further testings.
As you can see a few weak test results comes up. if I haven't done anything wrong when implementing Mellissas algorithm, it does not seem to be the best PRNG available today as she claims.
Ah yes. Heard of that. I don't think it existed when I last played with diehard.
Funny aside:
In the days of CD's George Marsaglia, creator of diehard and many PRNGs, published a CD with diehard on it. The CD also contained 100's megabytes of random bits.
Problem was that when George created the CD content he was using MSDOS and copied the files without using the "binary" option to the copy command. (/b was it?). MSDOS copied the file as text and fixed up all that it thought was line ending in the binary data. Replacing 0x0d with 0x0d, 0x0a or whatever it does.
Result: The random files on George's CD did not do very well in the diehard test!
I was nerdy enough to copy the files off the CD and fix the damage. Then the files passed diehard very well
I wrapped xoroshiro128+ PRNG into a simple test which generates a million numbers and prints the first and last 4. You could check if your PASM version does the same. Be sure to use the same seed of course.
First the results:
First 4 and last 4 of 1000000 xoroshiro128plus PRNG output (hex):
4aa4921626d12792
da319ec1da35800a
6a392789cef68c3c
eb50047a5d895c50
...
26fa38e131ff753b
f4cf7cfb892c43a3
56575790aa078000
438948e55200ef1a
From seed: s[0] = 730358127afd03f7, s[1] = d7a13a03abd4239b
@Chip
I don't want to add any more time to the P2 project, so don't wait for us to decide which one of the multitudes of PRNG's that is the best. Just go with Xoroshiro 128+ and it will endlessly much better than a simple LFSR!
The internal state is 128 bits, but all bits but the LSB is good as a tap for the final 32 bit value. That will fix the problem of the generator never returning a zero!
And to be honest everything points in favour of Xoroshiro 128+ according to all comparisons I have come across. Fastest (according to many implementations/tests, but that is only interesting from a software perspective though), least trouble with the more advanced test suites, just 128 bits of state memory and maybe most importantly it is completely free (in every sense of the word) to implement.
EDIT: Ignore the following it's gibberish.
Not sure I follow. Surely to check by brute force that the output is never zero we have to run through all the outputs of the 64 b generator:
I read that does cycle through all possible 64 bit output values except zero.
That implies that whatever 32 bits one selects from the 64 bit result a 32 bit zero is very possible.
I think if one only wants a 32 bit output then one has to check those 32 bits for zero and discard them if zero and try again.
Here is a translation to Spin as I understand the Verilog. There is a lot of bit manipulation, so I use the trick with the unimplemented PortB registers to access single bits in a long:
VAR
LONG rndx,rnd
PUB Main
rndx := -1
repeat
DIRB := rndx
rndx := rndx<<1 + (DIRB[31] ^ DIRB[10] ^ DIRB[4] ^ DIRB[1])
'Bit reorder
DIRB := rndx
repeat i from 31 to 0
OUTB[i] := DIRB[lookupz(31-i : 23,7,25,8,4,9,11,3,15,31,10,6,5,2,26,18,20,28,16,17,0,27,22,13,14,30,1,29,12,19,21,24)]
'cog pattern
rnd := OUTB ^ $428A2F98 'for cog0
'output rnd here
It's untested, I have not even tried to compile it!
Maybe the quality of the random generator is not affected by the bit reordering, and it's enough to test only the rndx calculation.
const mostly does nothing for modern C++ compilers. It's a hint at best.
It can be cast away anywhere in the codebase, so it's not a reliable thing for the optimizing compiler anyway.
I think you were thinking of "register" -- that's ignored by modern C++ compilers. "const" on the other hand certainly does have an effect; the compiler will give an error if you try to modify a const object, for example, and the optimizer is free to assume that consts do not change. It is true, as you pointed out, that const is easily cast away, but that's dangerous. If you tell the compiler something is const it's free to optimize based on that assumption (and GCC, at least, will do so).
Practically, if Chip want's to use xoroshiro128+ in PASM then we need to know the PASM works correctly.
I have taken the original xoroshiro128+ C source and used it to generate test data that any PASM version can be checked against.
The only remaining doubt is that the authors of xoroshiro128+ do not provide any sample output. So we have to trust that GCC, say, does the right thing with the same source.
Perhaps someone else would like to reproduce what I have done on whatever machine/compiler they have?
const mostly does nothing for modern C++ compilers. It's a hint at best.
It can be cast away anywhere in the codebase, so it's not a reliable thing for the optimizing compiler anyway.
I think you were thinking of "register" -- that's ignored by modern C++ compilers. "const" on the other hand certainly does have an effect; the compiler will give an error if you try to modify a const object, for example, and the optimizer is free to assume that consts do not change. It is true, as you pointed out, that const is easily cast away, but that's dangerous. If you tell the compiler something is const it's free to optimize based on that assumption (and GCC, at least, will do so).
Eric
No, I meant const, and I meant as it relates to the code generation and optimization. Yes it does introduce compile errors and protections at the source/compile time levels.
I was implementing the xoroshiro and doing some tests running the PASM implementation when I realized there was an error in my code: In those REPeat blocks which make the 64-bit rotators, the first RCL instructions needed a WC. The carry was not propagating into the top long. I fixed the code in my post, so you should copy the new version if you want to run it.
@Chip
I don't want to add any more time to the P2 project, so don't wait for us to decide which one of the multitudes of PRNG's that is the best. Just go with Xoroshiro 128+ and it will endlessly much better than a simple LFSR!
The internal state is 128 bits, but all bits but the LSB is good as a tap for the final 32 bit value. That will fix the problem of the generator never returning a zero!
And to be honest everything points in favour of Xoroshiro 128+ according to all comparisons I have come across. Fastest (according to many implementations/tests, but that is only interesting from a software perspective though), least trouble with the more advanced test suites, just 128 bits of state memory and maybe most importantly it is completely free (in every sense of the word) to implement.
/Johannes
The Verilog is done and now I'm plugging it in.
Ahle2, thanks a lot for this xoroshiro128+ pointer. This is a huge upgrade to what we had.
Evanh
Have you tried your zener TRNG with some RNG test suites? It would be cool to see how well it performs. I guess It would pass with Flying colors!
Nothing more than general knowledge on my behalf, sorry.
Comments
.. and Chips P2ASM too ?
There is some mention above that was not quite xoroshiro 64b ?
Do you mean here update in verilog ?
What is the easiest way to run some decent tests on a generator?
Ages ago I used diehard occasionally, it always seemed a pain to work with. I just took a look at the testu01 and, well, the user manual is a monster.
All I want is to feed a giga byte of random in and get a "good, bad, ugly" result out !
I have a transistor avalanche random generator here that will need testing when I get it's output into a computer some how.
I wondered about that.
One could run a zenner or transistor noise generator off a battery, have the whole thing in a metal box with an optical output.
All getting a bit over the top.
Not what you want for an on chip random generator !
-Phil
I think the ADC feedback will have lots of thermal noise represented in it.
"What is the easiest way to run some decent tests on a generator?"
My way of doing it is with a tool that outputs random characters to stdout. Then you could pipe the output to a file or directly to Dieharder in raw input mode! I'm currently tryging to figure out how to run TestU01 with my tool. All "experts" says that TestU01 is a superior test battery for deciding between a "great PRNG" and a "superior PRNG". My initial testings indicates that all mentioned PRNG in this threads passes the Dieharder tests. But I have not been able to test Chips LFSR yet. Btw, I'm talking about DiehardER not Diehard as that is considered "Smile" by todays standard.
@all
I have included the C++ source code for my testing tool. It would be nice if someone with knowledge in both C++ and Verilog could help me implement Chips LFSR, so we could use that as a reference for further testings.
/Johannes
1 means Xoroshiro in this case.
/Johannes
As you can see a few weak test results comes up. if I haven't done anything wrong when implementing Mellissas algorithm, it does not seem to be the best PRNG available today as she claims.
/Johannes
Funny aside:
In the days of CD's George Marsaglia, creator of diehard and many PRNGs, published a CD with diehard on it. The CD also contained 100's megabytes of random bits.
Problem was that when George created the CD content he was using MSDOS and copied the files without using the "binary" option to the copy command. (/b was it?). MSDOS copied the file as text and fixed up all that it thought was line ending in the binary data. Replacing 0x0d with 0x0d, 0x0a or whatever it does.
Result: The random files on George's CD did not do very well in the diehard test!
I was nerdy enough to copy the files off the CD and fix the damage. Then the files passed diehard very well
Slippery things, random numbers.
Thanks for the heads up on dieharder.
I don't recall diehard classifying test results, PASSED, WEAK, etc so nicely. One had to look at the numbers and make a decision.
I wrapped xoroshiro128+ PRNG into a simple test which generates a million numbers and prints the first and last 4. You could check if your PASM version does the same. Be sure to use the same seed of course.
First the results:
And test code:
(The xoroshiro128 source file comes from here: http://xoroshiro.di.unimi.it)
I don't want to add any more time to the P2 project, so don't wait for us to decide which one of the multitudes of PRNG's that is the best. Just go with Xoroshiro 128+ and it will endlessly much better than a simple LFSR!
The internal state is 128 bits, but all bits but the LSB is good as a tap for the final 32 bit value. That will fix the problem of the generator never returning a zero!
And to be honest everything points in favour of Xoroshiro 128+ according to all comparisons I have come across. Fastest (according to many implementations/tests, but that is only interesting from a software perspective though), least trouble with the more advanced test suites, just 128 bits of state memory and maybe most importantly it is completely free (in every sense of the word) to implement.
/Johannes
Is this what you had in mind? A thirty two bit output version of the xoroshiro128+ test.
This shifts the 64 bit result right by one and outputs the low 32 bits.
Sadly the authors of xoroshiro don't provide any test data. We have to trust our compiler is correct.
The results; The code:
Edit: Changed the seed to that used by Chip.
Not sure I follow. Surely to check by brute force that the output is never zero we have to run through all the outputs of the 64 b generator:
I read that does cycle through all possible 64 bit output values except zero.
That implies that whatever 32 bits one selects from the 64 bit result a 32 bit zero is very possible.
I think if one only wants a 32 bit output then one has to check those 32 bits for zero and discard them if zero and try again.
Love that old Dilbert.
Is zero not an acceptable random value? Or do you mean "reject zero in your code when you don't want zero as a random value"?
I don't understand Verilog. Is there a spin version I could use as a base to convert to C?
Here is a translation to Spin as I understand the Verilog. There is a lot of bit manipulation, so I use the trick with the unimplemented PortB registers to access single bits in a long: It's untested, I have not even tried to compile it!
Maybe the quality of the random generator is not affected by the bit reordering, and it's enough to test only the rndx calculation.
I think we should verify this before the P2 goes into synthesis. Will give us enough time to discuss every aspect of SPIN2 ...
Andy
I think you were thinking of "register" -- that's ignored by modern C++ compilers. "const" on the other hand certainly does have an effect; the compiler will give an error if you try to modify a const object, for example, and the optimizer is free to assume that consts do not change. It is true, as you pointed out, that const is easily cast away, but that's dangerous. If you tell the compiler something is const it's free to optimize based on that assumption (and GCC, at least, will do so).
Eric
I have taken the original xoroshiro128+ C source and used it to generate test data that any PASM version can be checked against.
The only remaining doubt is that the authors of xoroshiro128+ do not provide any sample output. So we have to trust that GCC, say, does the right thing with the same source.
Perhaps someone else would like to reproduce what I have done on whatever machine/compiler they have?
So that we can cross-check.
No, I meant const, and I meant as it relates to the code generation and optimization. Yes it does introduce compile errors and protections at the source/compile time levels.
With the scan-register macros, it's easier to look at:
The Verilog is done and now I'm plugging it in.
Ahle2, thanks a lot for this xoroshiro128+ pointer. This is a huge upgrade to what we had.