Skip to content

Commit f0c3eaa

Browse files
committed
Add support to xorshift PRNG
1 parent c0d3a1c commit f0c3eaa

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

lib/utils.c

+12
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,18 @@ poor_prng(unsigned int *seed)
614614
return shuffle;
615615
}
616616

617+
/*
618+
* XorShift*
619+
*/
620+
uint32_t
621+
xorshift_prng(uint64_t *state)
622+
{
623+
*state ^= *state >> 12;
624+
*state ^= *state << 25;
625+
*state ^= *state >> 27;
626+
return (*state * 0x2545F4914F6CDD1DULL) >> 32;
627+
}
628+
617629
/*
618630
* Copy string src to buffer dst of size dsize. At most dsize-1
619631
* chars will be copied. Always NUL terminates (unless dsize == 0).

lib/utils.h

+1
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ extern uint32_t adler_crc32(uint8_t *, size_t);
155155
extern uint32_t fletcher_crc32(uint8_t *, size_t);
156156
extern int integer_to_string(const int, char *, size_t);
157157
extern uint32_t poor_prng(unsigned int *);
158+
extern uint32_t xorshift_prng(uint64_t *);
158159
extern size_t strlcpy(char *, const char *, size_t);
159160

160161
#endif

0 commit comments

Comments
 (0)