# What's the fastest way to fill an array with random bits without using private Random.jl internals?

**URL:** https://discourse.julialang.org/t/whats-the-fastest-way-to-fill-an-array-with-random-bits-without-using-private-random-jl-internals/135089
**Category:** Performance
**Created:** [January 15, 2026, 11:34pm UTC](https://discourse.julialang.org/t/whats-the-fastest-way-to-fill-an-array-with-random-bits-without-using-private-random-jl-internals/135089 "2026-01-15T23:34:26Z")
**Posts on this page:** 1
**Showing post:** 13

<div class="post-metadata">

### Author: ![mikmoore](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mikmoore/32/31109_2.png) [@mikmoore](https://discourse.julialang.org/u/mikmoore)
#### Post date: [January 20, 2026, 3:47pm UTC](https://discourse.julialang.org/t/whats-the-fastest-way-to-fill-an-array-with-random-bits-without-using-private-random-jl-internals/135089/13 "2026-01-20T15:47:25Z")

</div>

> [@npbarnes](#):
>
> Without going into too many algorithmic details, to make one sample you generate a UInt64, then do some table look ups, math, etc and 99% of the time you get a result otherwise you regenerate the UInt64 and retry

This reminds me of some stuff I was looking at a few years ago [as part of a discussion on the distribution of `rand`](https://discourse.julialang.org/t/output-distribution-of-rand-float32-and-rand-float64-thread-2/105184/435). In that version, I would SIMD-compute a batch of values at a time, then refine any of them that needed further work (but still in parallel, using a mask to prevent overwriting finalized values). So I did everything in one pass rather than two and entirely with SIMD.

The thing `Random.jl` is missing to make that nice is a fast function for generating a block (i.e., tuple) of random bits (which should use an immutable version of the random state to avoid frequent memory writebacks). There’s space for an internal (and maybe eventually public) function to do this. Ideally, a lot of the existing vectorized random generators would change to use it as well (they already do this, but inline in a way that’s difficult to use generically).

Think about what such an interface would need to do to support your use case. Such an interface might be worth adding eventually.

---

_[View the full topic](https://discourse.julialang.org/t/whats-the-fastest-way-to-fill-an-array-with-random-bits-without-using-private-random-jl-internals/135089)._
