Skip to content

Instantly share code, notes, and snippets.

@Marc-B-Reynolds
Last active August 29, 2015 14:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Marc-B-Reynolds/0b5f1db5ad7a3e453596 to your computer and use it in GitHub Desktop.
Save Marc-B-Reynolds/0b5f1db5ad7a3e453596 to your computer and use it in GitHub Desktop.
/*
Experiemental versions of improving the stat properties of a 32-bit (for embedded devices) xorshift
without restorting to adding state data. The two versions add one to the dependency chain.
Based directly on the work of Sebastiano Vigna - http://xorshift.di.unimi.it/
*/
uint32_t state = 1;
// Off the shelf xorshift.
// failures from small crush
// 1 BirthdaySpacings
// 2 Collision
// 6 MaxOft
// 8 MatrixRank
// 10 RandomWalk1 H
// failures from small crush (bit reversed)
// 1 BirthdaySpacings
// 6 MaxOft
// 8 MatrixRank
// 10 RandomWalk1 H
// 10 RandomWalk1 M
// 10 RandomWalk1 J
// 10 RandomWalk1 R
// 10 RandomWalk1 C
uint32_t xorshift32(void)
{
state ^= (state << 13);
state ^= (state >> 17);
state ^= (state << 5);
return state;
}
// Based on: Further scramblings of Marsaglia's xorshift generators.
// failures from small crush
// 1 BirthdaySpacings
// failures from small crush (bit reversed)
// 1 BirthdaySpacings
// 2 Collision
// 6 MaxOft
uint32_t xorshift32a(void)
{
int s0 = state;
state ^= (state << 13);
state ^= (state >> 17);
state ^= (state << 5);
return state + s0;
}
// Based on: An experimental exploration of Marsaglia's xorshift generators, scrambled
// failures from small crush
// 1 BirthdaySpacings
// failures from small crush (bit reversed)
// 1 BirthdaySpacings
// 6 MaxOft
uint32_t xorshift32m(void)
{
state ^= (state << 13);
state ^= (state >> 17);
state ^= (state << 5);
return state*1597334677;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment