# \#rng

**URL:** https://discourse.julialang.org/tag/rng/741.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [How to ensure reproducibility when using CUDA.rand()?](https://discourse.julialang.org/t/how-to-ensure-reproducibility-when-using-cuda-rand/135987)

<div class="topic-metadata">

**Author:** [@WG-ZHENG](https://discourse.julialang.org/u/WG-ZHENG)\
**Replies:** 3\
**Last updated:** [March 3, 2026, 9:19am UTC](https://discourse.julialang.org/t/how-to-ensure-reproducibility-when-using-cuda-rand/135987 "2026-03-03T09:19:32Z")

</div>

It seems that it is not supported to pass a specified rng as argument to rand in CUDA.jl. The codes below raise an error: using CUDA rng = CUDA.RNG(42) a = CUDA.rand(rng, 1) ERROR: MethodError: no method matching rand…

---

## [How to change the default RNG for a given script?](https://discourse.julialang.org/t/how-to-change-the-default-rng-for-a-given-script/132481)

<div class="topic-metadata">

**Author:** [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Replies:** 7\
**Last updated:** [September 19, 2025, 2:28pm UTC](https://discourse.julialang.org/t/how-to-change-the-default-rng-for-a-given-script/132481 "2025-09-19T14:28:35Z")

</div>

I know I can pass RNG to many (all?) stochastic functions, and that StableRNG is slow, but is there a way I can set at the beginning of my model something like: random\_seed = 123 # from a config file Random.GLO…

---

## [How to get rid of allocations in this simple filtered generator example?](https://discourse.julialang.org/t/how-to-get-rid-of-allocations-in-this-simple-filtered-generator-example/124847)

<div class="topic-metadata">

**Author:** [@marius311](https://discourse.julialang.org/u/marius311)\
**Replies:** 3\
**Last updated:** [January 22, 2025, 6:45pm UTC](https://discourse.julialang.org/t/how-to-get-rid-of-allocations-in-this-simple-filtered-generator-example/124847 "2025-01-22T18:45:43Z")

</div>

Here’s a MWE of the allocating code (Julia 1.11.2): function foo() arr = \[Ref(i) for i=1:100\] iter = (i for i in arr if rand()\>0) @time begin elem, state = iterate(iter) while true …

---

## [Linear relationship between Xoshiro tasks](https://discourse.julialang.org/t/linear-relationship-between-xoshiro-tasks/110454)

<div class="topic-metadata">

**Author:** [@foobar\_lv2](https://discourse.julialang.org/u/foobar_lv2)\
**Replies:** 29\
**Last updated:** [March 6, 2024, 4:39pm UTC](https://discourse.julialang.org/t/linear-relationship-between-xoshiro-tasks/110454 "2024-03-06T16:39:36Z")

</div>

Cool, I didn’t see that! Quite sweet addition to my initial unprincipled PR. However, I fear that your construction is somewhat broken. The problem is that you can easily construct task trees that imply linear relatio…

---

## [Seemingly nondeterministic behavior despite setting Random.seed!()?](https://discourse.julialang.org/t/seemingly-nondeterministic-behavior-despite-setting-random-seed/85880)

<div class="topic-metadata">

**Author:** [@johnabs](https://discourse.julialang.org/u/johnabs)\
**Replies:** 7\
**Last updated:** [August 18, 2022, 5:33am UTC](https://discourse.julialang.org/t/seemingly-nondeterministic-behavior-despite-setting-random-seed/85880 "2022-08-18T05:33:11Z")

</div>

Hi all, I’m working on an optimization problem on graphs using some code I ported from R to Julia. What’s strange, is that when I run the code which uses stochastic processes to sample a solution space in a search for …

---

## [\[ANN\] ChaChaCiphers.jl: fast cryptographic RNG and stream ciphers](https://discourse.julialang.org/t/ann-chachaciphers-jl-fast-cryptographic-rng-and-stream-ciphers/81069)

<div class="topic-metadata">

**Author:** [@kernelmethod](https://discourse.julialang.org/u/kernelmethod)\
**Replies:** 3\
**Last updated:** [May 17, 2022, 9:37am UTC](https://discourse.julialang.org/t/ann-chachaciphers-jl-fast-cryptographic-rng-and-stream-ciphers/81069 "2022-05-17T09:37:49Z")

</div>

ChaChaCiphers.jl I’m happy to announce ChaChaCiphers.jl, a pure-Julia implementation of the ChaCha stream cipher family. This package aims to provide fast, cryptographically-secure, and reproducible random number gener…

---

## [Best way to generate random floats over a wide range of magnitudes](https://discourse.julialang.org/t/best-way-to-generate-random-floats-over-a-wide-range-of-magnitudes/74129)

<div class="topic-metadata">

**Author:** [@swishmas](https://discourse.julialang.org/u/swishmas)\
**Replies:** 2\
**Last updated:** [January 6, 2022, 12:10pm UTC](https://discourse.julialang.org/t/best-way-to-generate-random-floats-over-a-wide-range-of-magnitudes/74129 "2022-01-06T12:10:15Z")

</div>

Simple question: rand() generally returns a random number rarely in the range (0,1E-1) and I am interested in a range of random numbers between (0,1E-2). I was wondering if anyone could verify that a solution like rand…

---

## [Very special RNG](https://discourse.julialang.org/t/very-special-rng/73242)

<div class="topic-metadata">

**Author:** [@wildart](https://discourse.julialang.org/u/wildart)\
**Replies:** 3\
**Last updated:** [December 17, 2021, 10:37am UTC](https://discourse.julialang.org/t/very-special-rng/73242 "2021-12-17T10:37:09Z")

</div>

Recently, I’ve seen an issue that mentioned using a “special” random number generator from XKCD-221. Unfortunately, I do not remember where it was. But, if you need such RNG, you can get it from here: Xkcd221.jl. It’s …

---

## [Return vector when broadcasting over mean vector to generate random numbers](https://discourse.julialang.org/t/return-vector-when-broadcasting-over-mean-vector-to-generate-random-numbers/68851)

<div class="topic-metadata">

**Author:** [@conorhassan](https://discourse.julialang.org/u/conorhassan)\
**Replies:** 2\
**Last updated:** [September 28, 2021, 7:16am UTC](https://discourse.julialang.org/t/return-vector-when-broadcasting-over-mean-vector-to-generate-random-numbers/68851 "2021-09-28T07:16:39Z")

</div>

Hi there, I am wanting to use something like rand.(Normal.(\[5;10\],1),1) where we have two different mean values \\mu\_1=5, \\mu\_2=10 which we broadcast over to generate 2 random numbers total. I would like the output to …

---

## [Store Random Number Generator outside Rand()](https://discourse.julialang.org/t/store-random-number-generator-outside-rand/67517)

<div class="topic-metadata">

**Author:** [@Albert\_Zevelev](https://discourse.julialang.org/u/Albert_Zevelev)\
**Replies:** 1\
**Last updated:** [September 1, 2021, 4:31pm UTC](https://discourse.julialang.org/t/store-random-number-generator-outside-rand/67517 "2021-09-01T16:31:26Z")

</div>

How can store an rng w/ seed outside of rand()? julia\> using Random, Distributions; julia\> rand(MersenneTwister(0), Normal()) 0.6791074260357777 julia\> rand(MersenneTwister(0), Normal()) 0.6791074260357777 julia\> rs=…

---

## [Making RNG's fast](https://discourse.julialang.org/t/making-rngs-fast/65129)

<div class="topic-metadata">

**Author:** [@viraltux](https://discourse.julialang.org/u/viraltux)\
**Replies:** 4\
**Last updated:** [July 22, 2021, 9:28pm UTC](https://discourse.julialang.org/t/making-rngs-fast/65129 "2021-07-22T21:28:16Z")

</div>

I am playing around with RNG’s, specifically this one: function squares(ctr::UInt64, key::UInt64)::UInt32 y = x = ctr \* key; z = y + key x = x\*x + y; x = (x\>\>32) | (x\<\<32) # round 1 x = x\*x + z; x = (…
