<commit_before>---
title: Random fun (xoroshiro)
published: true
tags: random c++ math quote
---
> Le hasard souvent fait plus que la science. - [_Proverbe Français_](https://citations.ouest-france.fr/citation-proverbe-francais/hasard-souvent-fait-science-80598.html)

![caption](https://thompsonsed.co.uk/wp-content/uploads/2019/03/prng_perf.jpg) 

### [xoroshiro128+](http://xoroshiro.di.unimi.it/) (XOR/shift/rotate) / [wikipedia](https://en.wikipedia.org/wiki/Xorshift#xorshift.2B)

> The lowest bits of the output generated by xoroshiro128+ have low quality. The authors of xoroshiro128+ acknowledge that it does not pass all statistical tests, stating: We suggest to use its upper bits for floating-point generation. 

> Xorshift128+ fails BigCrush when selecting the least significant 32 bits and reversing the bit order. -   [The Xorshift128+ random number generator fails BigCrush](https://lemire.me/blog/2017/09/08/the-xorshift128-random-number-generator-fails-bigcrush/)


- [What is performance-wise the best way to generate random bools?]( https://stackoverflow.com/a/35358644/51386)

{% highlight cpp %}
#include <random>

random_device rd;
/* The state must be seeded so that it is not everywhere zero. */
uint64_t s[2] = { (uint64_t(rd()) << 32) ^ (rd()),<commit_msg>Update 2017-12-22-random.md<commit_after>---
title: Random fun (xoroshiro)
published: true
tags: random c++ math quote
---
> Le hasard souvent fait plus que la science. - [_Proverbe Français_](https://citations.ouest-france.fr/citation-proverbe-francais/hasard-souvent-fait-science-80598.html)

![caption](https://thompsonsed.co.uk/wp-content/uploads/2019/03/prng_perf.jpg) 

### [xoroshiro128+](http://xoroshiro.di.unimi.it/) (XOR/shift/rotate) / [wikipedia](https://en.wikipedia.org/wiki/Xorshift#xorshift.2B)

> The lowest bits of the output generated by xoroshiro128+ have low quality. The authors of xoroshiro128+ acknowledge that it does not pass all statistical tests, stating: We suggest to use its upper bits for floating-point generation. 

> Xorshift128+ fails BigCrush when selecting the least significant 32 bits and reversing the bit order... The recommended replacement for xorshift128+, xoroshiro128+, also fails BigCrush in a similar manner -   [The Xorshift128+ random number generator fails BigCrush](https://lemire.me/blog/2017/09/08/the-xorshift128-random-number-generator-fails-bigcrush/)


- [What is performance-wise the best way to generate random bools?]( https://stackoverflow.com/a/35358644/51386)

{% highlight cpp %}
#include <random>

random_device rd;
/* The state must be seeded so that it is not everywhere zero. */
uint64_t s[2] = { (uint64_t(rd()) << 32) ^ (rd()),
{'fraction_non_alphanumeric': 0.1274692508386135, 'fraction_numerical': 0.049944092433842714, 'mean_word_length': 4.674418604651163, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 10, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2615150', 'n_tokens_mistral': 987, 'n_tokens_neox': 861, 'n_words': 249}