# Random seed initialization with splitmix

**URL:** https://discourse.julialang.org/t/random-seed-initialization-with-splitmix/110426
**Category:** General Usage
**Tags:** random
**Created:** [February 19, 2024, 10:34pm UTC](https://discourse.julialang.org/t/random-seed-initialization-with-splitmix/110426 "2024-02-19T22:34:38Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Enlil50](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/enlil50/32/206539_2.png) [@Enlil50](https://discourse.julialang.org/u/Enlil50)
#### Post date: [February 19, 2024, 10:34pm UTC](https://discourse.julialang.org/t/random-seed-initialization-with-splitmix/110426/1 "2024-02-19T22:34:38Z")

</div>

I know that to use Xoshiro256++ is better to randomize the seed with a fast rng as splitmix. This enables us to generate the 4 states of xoshiro256++.  
Is this done by default?

---

<div class="post-metadata">

### Author: ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)
#### Post date: [February 20, 2024, 12:14am UTC](https://discourse.julialang.org/t/random-seed-initialization-with-splitmix/110426/2 "2024-02-20T00:14:19Z")

</div>

Yes:

> <https://github.com/JuliaLang/julia/blob/02699bb6cd83d16b1e51e2fb127241e18df7c56b/src/task.c#L854>

Although I figured out a way to majorly simplify the splitmix algorithm so that it doesn’t require arithmetic in a prime modulus, all explained in that massive comment.

---

<div class="post-metadata">

### Author: ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)
#### Post date: [February 20, 2024, 3:26am UTC](https://discourse.julialang.org/t/random-seed-initialization-with-splitmix/110426/3 "2024-02-20T03:26:05Z")

</div>

If you’re asking about the initial seeding rather than the task splitting, then we do way better and use SHA256 to go from user-provided seeds to create the actual RNG state.

---

<div class="post-metadata">

### Author: ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)
#### Post date: [February 20, 2024, 3:44am UTC](https://discourse.julialang.org/t/random-seed-initialization-with-splitmix/110426/4 "2024-02-20T03:44:51Z")

</div>

Have you thought about putting that comment on arxiv?

---

<div class="post-metadata">

### Author: ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)
#### Post date: [February 20, 2024, 2:04pm UTC](https://discourse.julialang.org/t/random-seed-initialization-with-splitmix/110426/5 "2024-02-20T14:04:00Z")

</div>

A post was split to a new topic: [Linear relationship between Xoshiro tasks](https://discourse.julialang.org/t/linear-relationship-between-xoshiro-tasks/110454)

---

<div class="post-metadata">

### Author: ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)
#### Post date: [February 20, 2024, 1:49pm UTC](https://discourse.julialang.org/t/random-seed-initialization-with-splitmix/110426/6 "2024-02-20T13:49:04Z")

</div>

Yeah, I’ve thought about writing it up. But making something into a paper is always so much extra work…

---

<div class="post-metadata">

### Author: ![caleb-allen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/caleb-allen/32/14054_2.png) [@caleb-allen](https://discourse.julialang.org/u/caleb-allen)
#### Post date: [February 21, 2024, 6:45pm UTC](https://discourse.julialang.org/t/random-seed-initialization-with-splitmix/110426/7 "2024-02-21T18:45:02Z")

</div>

> <https://github.com/JuliaLang/julia/blob/02699bb6cd83d16b1e51e2fb127241e18df7c56b/src/task.c#L903-L910>

Wow, this feels like a magic trick!

---

<div class="post-metadata">

### Author: ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)
#### Post date: [February 21, 2024, 7:02pm UTC](https://discourse.julialang.org/t/random-seed-initialization-with-splitmix/110426/8 "2024-02-21T19:02:16Z")

</div>

It does, right?! But task forks are inherently binary—each task only forks one child at a time—so it really felt like there had to be some way to make the task coordinates binary. The tricky bit is that you have a choice of somewhat unintuitive ways of thinking about binary “pedigree” coordinates:

1. The parent task’s coordinates changing every time it spawns a child—weird since shouldn’t a tasks have a fixed coordinate?
2. Upon fork, parent task is actually replaced by two children—the actual child, and a replacement of itself that is in practice the same object, but is theoretically different with a longer coordinate tuple. This is also weird.
3. Or each task has infinite coordinates, that are all zeros beyond some point. That’s how I formalize it in my proof in the other thread.

Despite the infinite part, I think the last option is the best: each task has a single, fixed (albeit infinite) coordinate tuple.
