Random Numbers

Discussion of anything and everything relating to chess playing software and machines.

Moderators: hgm, Rebel, chrisw

User avatar
Dan Honeycutt
Posts: 5258
Joined: Mon Feb 27, 2006 4:31 pm
Location: Atlanta, Georgia

Random Numbers

Post by Dan Honeycutt »

Hi All,

If you're in the market for a good 64 bit pseudo random number generator my post in CTF, "So. Many. Passwords." may be of interest. I'm working on an encryption application - if you know something about encryption (I don't) I'd also like to hear your comments.

Best
Dan H.
mar
Posts: 2554
Joined: Fri Nov 26, 2010 2:00 pm
Location: Czech Republic
Full name: Martin Sedlak

Re: Random Numbers

Post by mar »

Dan Honeycutt wrote:Hi All,

If you're in the market for a good 64 bit pseudo random number generator my post in CTF, "So. Many. Passwords." may be of interest. I'm working on an encryption application - if you know something about encryption (I don't) I'd also like to hear your comments.

Best
Dan H.
Here's mine, proven to be good (real world scenarios):

Code: Select all

ULong keys[2];

inline ULong Rotate(ULong v, Byte s) {
	return &#40;v >> s&#41; | &#40;v << &#40;64-s&#41;);
&#125;

// generate next 64-bit random number
inline ULong Next64&#40;)
&#123;
	ULong tmp = keys&#91;0&#93;;
	keys&#91;0&#93; += Rotate&#40;keys&#91;1&#93; ^ 0xc5462216u ^ (&#40;ULong&#41;0xcf14f4ebu<<32&#41;, 1&#41;;
	return keys&#91;1&#93; += Rotate&#40;tmp ^ 0x75ecfc58u ^ (&#40;ULong&#41;0x9576080cu<<32&#41;, 9&#41;;
&#125;
where ULong = uint64_t
IV is two 64-bit numbers (keys) so seed with whatever you want.
If your compiler can fold rotations (last time I tried with clang it couldn't), it can generate ~1 billion 64-bit PRN per second on my several years old stock i7 quad (single core).

public domain.

Of course it's not crypto-secure so I'm not sure what you want to accomplish. Generates sequence to xor input data with? Might work as a naive encryption.
Milos
Posts: 4190
Joined: Wed Nov 25, 2009 1:47 am

Re: Random Numbers

Post by Milos »

Dan Honeycutt wrote:Hi All,

If you're in the market for a good 64 bit pseudo random number generator my post in CTF, "So. Many. Passwords." may be of interest. I'm working on an encryption application - if you know something about encryption (I don't) I'd also like to hear your comments.
https://en.wikipedia.org/wiki/Mersenne_Twister
Dann Corbit
Posts: 12540
Joined: Wed Mar 08, 2006 8:57 pm
Location: Redmond, WA USA

Re: Random Numbers

Post by Dann Corbit »

Taking ideas is not a vice, it is a virtue. We have another word for this. It is called learning.
But sharing ideas is an even greater virtue. We have another word for this. It is called teaching.
User avatar
Dan Honeycutt
Posts: 5258
Joined: Mon Feb 27, 2006 4:31 pm
Location: Atlanta, Georgia

Re: Random Numbers

Post by Dan Honeycutt »

mar wrote:Of course it's not crypto-secure so I'm not sure what you want to accomplish. Generates sequence to xor input data with? Might work as a naive encryption.
What I'm working on is a very simple text editor with a password feature to use to store the many passwords you end up with if you are active on the internet. I'm an encryption noob, what advantage would a crypto-secure RNG give, just harder to decrypt?

Best
Dan H.
User avatar
Dan Honeycutt
Posts: 5258
Joined: Mon Feb 27, 2006 4:31 pm
Location: Atlanta, Georgia

Re: Random Numbers

Post by Dan Honeycutt »

Milos wrote:
Dan Honeycutt wrote:Hi All,

If you're in the market for a good 64 bit pseudo random number generator my post in CTF, "So. Many. Passwords." may be of interest. I'm working on an encryption application - if you know something about encryption (I don't) I'd also like to hear your comments.
https://en.wikipedia.org/wiki/Mersenne_Twister
I've read that Kiss is something of an improvement over the Mersenne Twister but I certainly don't know enough to attest one way or the other.

Best
Dan H.
User avatar
Dan Honeycutt
Posts: 5258
Joined: Mon Feb 27, 2006 4:31 pm
Location: Atlanta, Georgia

Re: Random Numbers

Post by Dan Honeycutt »

Thanks, Dann. I'm still trying to understand if I really need a crypto-secure RNG but if I do your second link looks like a good candidate.

Best
Dan H.
Dann Corbit
Posts: 12540
Joined: Wed Mar 08, 2006 8:57 pm
Location: Redmond, WA USA

Re: Random Numbers

Post by Dann Corbit »

Dan Honeycutt wrote:
mar wrote:Of course it's not crypto-secure so I'm not sure what you want to accomplish. Generates sequence to xor input data with? Might work as a naive encryption.
What I'm working on is a very simple text editor with a password feature to use to store the many passwords you end up with if you are active on the internet. I'm an encryption noob, what advantage would a crypto-secure RNG give, just harder to decrypt?

Best
Dan H.
If you want to handle passwords, you NEED a crypto secure method.
Especially since users tend to reuse passwords.
Taking ideas is not a vice, it is a virtue. We have another word for this. It is called learning.
But sharing ideas is an even greater virtue. We have another word for this. It is called teaching.
kbhearn
Posts: 411
Joined: Thu Dec 30, 2010 4:48 am

Re: Random Numbers

Post by kbhearn »

When it comes to cryptography there's so many ways to mess it up that you really shouldn't roll your own anyways for anything other than educational purposes - take an existing crypto library, use it as intended. Even your own implementation of an accepted protocol is risky (your implementation may 'work' while not being secure against subtle attacks) - heavily used crypto libraries you at least have the peace of mind that many people are looking for and fixing these vulnerabilities.
Lyudmil Tsvetkov
Posts: 6052
Joined: Tue Jun 12, 2012 12:41 pm

Re: Random Numbers

Post by Lyudmil Tsvetkov »

one more thread, when one wonders, especially when posted by a mod, whether it belongs strictly here.

in any case, I see nothing related to computer chess: the use is not intended to tackle building a chess engine and, even if it were so, still the rigth forum would be the programming section.

on the other hand, I find Harvey's London chess classic thread quite acceptable, as people are using engine output to decide on a position.