title: Fastest way to generate random numbers
body: <p>libc has <a href="http://man7.org/linux/man-pages/man3/random.3.html" rel="noreferrer"><code>random</code></a> which</p>
  
  <blockquote>
    <p>uses a nonlinear additive feedback random number generator employing a default table of size 31 long integers to return successive pseudo-random numbers</p>
  </blockquote>
  
  <p>I'm looking for a random function written in Rust with the same speed. It doesn't need to be crypto-safe, pseudo-random is good enough.</p>
  
  <p>Looking through the <a href="https://doc.rust-lang.org/rand/rand/index.html" rel="noreferrer"><code>rand crate</code></a> it seems that <a href="https://doc.rust-lang.org/rand/rand/struct.XorShiftRng.html" rel="noreferrer"><code>XorShiftRng</code></a> is the closest fit to this need: </p>
  
  <blockquote>
    <p>The Xorshift algorithm is not suitable for cryptographic purposes but is very fast</p>
  </blockquote>
  
  <p>When I use it like this:</p>
  
  <pre><code>extern crate time;
  use rand::Rng;
  
  let mut rng = rand::XorShiftRng::new_unseeded();
  rng.next_u64();
  </code></pre>
  
  <p>it is about 33% slower than libc's random. (<a href="http://play.integer32.com/?gist=de0c94e53cdbb04e9dd673ae90a82d3d&amp;version=nightly" rel="noreferrer">Sample code generating 8'000'000 random numbers</a>).</p>
  
  <p>In the end, I'll need <code>i64</code> random numbers, so when I run <code>rng.gen()</code> this is already 100% slower than libc's random. When casting with <code>rng.next_u64() as i64</code>, then is is 60% slower.</p>
  
  <p>Is there any way to achieve the same speed in rust without using any <code>unsafe</code> code?</p>