Skip to content

Commit 4d2cc94

Browse files
author
kennyledet
committed
Merge pull request kennyledet#3 from stolendata/patch-1
Create ranrotb_prng.h
2 parents 2918374 + 88775bd commit 4d2cc94

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
RANROT-B/32 PRNG
3+
4+
Call with 1 or higher to set seed; call with 0 to fetch values.
5+
6+
Robin Leffmann 2005 / <robin at stolendata dot net>
7+
*/
8+
9+
#include <stdint.h>
10+
11+
static uint32_t rrbRand( uint32_t rrbSeed )
12+
{
13+
static uint32_t rrbLo, rrbHi;
14+
15+
if( rrbSeed != 0 )
16+
{
17+
rrbLo = rrbSeed;
18+
rrbHi = ~rrbSeed;
19+
}
20+
else
21+
{
22+
rrbHi = ( rrbHi << 16 ) + ( rrbHi >> 16 );
23+
rrbHi += rrbLo;
24+
rrbLo += rrbHi;
25+
}
26+
27+
return rrbHi;
28+
}

0 commit comments

Comments
 (0)