# \#random

**URL:** https://discourse.julialang.org/tag/random/637.md

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

---

## [How to initialize/fix the RNG seed on the GPU?](https://discourse.julialang.org/t/how-to-initialize-fix-the-rng-seed-on-the-gpu/133831)

<div class="topic-metadata">

**Author:** [@jwtkeeble](https://discourse.julialang.org/u/jwtkeeble)\
**Replies:** 4\
**Last updated:** [November 13, 2025, 7:27pm UTC](https://discourse.julialang.org/t/how-to-initialize-fix-the-rng-seed-on-the-gpu/133831 "2025-11-13T19:27:07Z")

</div>

Hi All, I have a question regarding initializing the random seed within CUDA.jl. I saw in this thread for the CURAND library, however, it seems the CURAND library is now deprecated for CUDA.jl. I do see there’s CUDA.de…

---

## [\[ANN\] SnakeBar.jl - A progress bar that fills your terminal with space-filling curves](https://discourse.julialang.org/t/ann-snakebar-jl-a-progress-bar-that-fills-your-terminal-with-space-filling-curves/133580)

<div class="topic-metadata">

**Author:** [@majoburo](https://discourse.julialang.org/u/majoburo)\
**Replies:** 2\
**Last updated:** [October 31, 2025, 4:58pm UTC](https://discourse.julialang.org/t/ann-snakebar-jl-a-progress-bar-that-fills-your-terminal-with-space-filling-curves/133580 "2025-10-31T16:58:25Z")

</div>

Hey everyone, I just released my first Julia package, SnakeBar.jl – a progress bar that draws a random space-filling curve per process in your terminal! Any comments are appreciated! Happy Halloween! Community reactio…

---

## [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…

---

## [Re \`seed!\` ing the RNG at each step of a simulation?](https://discourse.julialang.org/t/re-seed-ing-the-rng-at-each-step-of-a-simulation/132158)

<div class="topic-metadata">

**Author:** [@nhz2](https://discourse.julialang.org/u/nhz2)\
**Replies:** 4\
**Last updated:** [September 7, 2025, 9:43pm UTC](https://discourse.julialang.org/t/re-seed-ing-the-rng-at-each-step-of-a-simulation/132158 "2025-09-07T21:43:26Z")

</div>

I am running long stochastic simulations that look like: sim\_name = "example/1" Random.seed!(sim\_name) ctx = setup(sim\_name) for frame in 1:1000 ctx = loop(ctx) end I need to be able to restart simulations that crash…

---

## [Why doesn't Random.seed! allocate for StableRNGs.LehmerRNG?](https://discourse.julialang.org/t/why-doesnt-random-seed-allocate-for-stablerngs-lehmerrng/130621)

<div class="topic-metadata">

**Author:** [@RoyW](https://discourse.julialang.org/u/RoyW)\
**Replies:** 1\
**Last updated:** [July 20, 2025, 9:36am UTC](https://discourse.julialang.org/t/why-doesnt-random-seed-allocate-for-stablerngs-lehmerrng/130621 "2025-07-20T09:36:09Z")

</div>

I ran the following code on my machine: import StableRNGs using BenchmarkTools, Random const T = Float64 rng = StableRNGs.LehmerRNG(0) rng2 = Random.Xoshiro(0) rng3 = Random.MersenneTwister(0) @btime randn($rng, T) @…

---

## [Matlab to Julia: Random number generators](https://discourse.julialang.org/t/matlab-to-julia-random-number-generators/129937)

<div class="topic-metadata">

**Author:** [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Replies:** 19\
**Last updated:** [June 17, 2025, 1:33pm UTC](https://discourse.julialang.org/t/matlab-to-julia-random-number-generators/129937 "2025-06-17T13:33:34Z")

</div>

I am writing unit tests for Matlab and Julia functions (Julia translated from Matlab), and both use the randn() function. Is there a way to get the same sequence of random numbers both in Matlab and Julia? Without that …

---

## [\`check-bounds=no\` causes illegal memory access when using \`rand()\` in CUDA kernel](https://discourse.julialang.org/t/check-bounds-no-causes-illegal-memory-access-when-using-rand-in-cuda-kernel/129455)

<div class="topic-metadata">

**Author:** [@0samuraiE](https://discourse.julialang.org/u/0samuraiE)\
**Replies:** 3\
**Last updated:** [May 31, 2025, 7:38am UTC](https://discourse.julialang.org/t/check-bounds-no-causes-illegal-memory-access-when-using-rand-in-cuda-kernel/129455 "2025-05-31T07:38:44Z")

</div>

I’m encountering an error when running the following minimal example with check-bounds=no. With bounds checking enabled (check-bounds=yes), it works fine. But disabling it causes: ERROR: CUDA error: an illegal memory ac…

---

## [Draw a random number through a probability distribution defined as an array](https://discourse.julialang.org/t/draw-a-random-number-through-a-probability-distribution-defined-as-an-array/129210)

<div class="topic-metadata">

**Author:** [@Torkel](https://discourse.julialang.org/u/Torkel)\
**Replies:** 5\
**Last updated:** [May 21, 2025, 10:40am UTC](https://discourse.julialang.org/t/draw-a-random-number-through-a-probability-distribution-defined-as-an-array/129210 "2025-05-21T10:40:30Z")

</div>

If I have an NxM matrix with decimal values (normalised so that the sum is 1): prob\_dens::Matrix{Float64.Float64} is there a good way to randomly draw an index i,j with probability corresponding to the probability dist…

---

## [Disable default rng](https://discourse.julialang.org/t/disable-default-rng/128790)

<div class="topic-metadata">

**Author:** [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Replies:** 10\
**Last updated:** [May 8, 2025, 11:26am UTC](https://discourse.julialang.org/t/disable-default-rng/128790 "2025-05-08T11:26:22Z")

</div>

In a test suite I want to make sure that the default RNG is never called (clarification: even indirectly, somewhere within a package), ie that all calls to rand & friends have an explicit rng as their first argument. Th…

---

## [Sprand fails to construct a SparseVector](https://discourse.julialang.org/t/sprand-fails-to-construct-a-sparsevector/128828)

<div class="topic-metadata">

**Author:** [@WalterMadelim](https://discourse.julialang.org/u/WalterMadelim)\
**Replies:** 3\
**Last updated:** [May 8, 2025, 6:36am UTC](https://discourse.julialang.org/t/sprand-fails-to-construct-a-sparsevector/128828 "2025-05-08T06:36:36Z")

</div>

I can construct a random SparseMatrixCSC, but not a SparseVector in the same way. Where am I wrong? julia\> using SparseArrays julia\> rfn = n -\> rand(-9:.1:9, n) #1 (generic function with 1 method) julia\> sprand(7, 8, …

---

## [My new random number generator](https://discourse.julialang.org/t/my-new-random-number-generator/128244)

<div class="topic-metadata">

**Author:** [@Tarny\_GG\_Channie](https://discourse.julialang.org/u/Tarny_GG_Channie)\
**Replies:** 3\
**Last updated:** [April 20, 2025, 6:51pm UTC](https://discourse.julialang.org/t/my-new-random-number-generator/128244 "2025-04-20T18:51:42Z")

</div>

Please note I’m not a professional rng designer so this might not be up to the standard, but feel free to check it out. It passes the smallcrush test. #= This is free and unencumbered software released into the public d…

---

## [Product distribution allocates (a lot)](https://discourse.julialang.org/t/product-distribution-allocates-a-lot/126771)

<div class="topic-metadata">

**Author:** [@JADekker](https://discourse.julialang.org/u/JADekker)\
**Replies:** 9\
**Last updated:** [March 11, 2025, 3:12pm UTC](https://discourse.julialang.org/t/product-distribution-allocates-a-lot/126771 "2025-03-11T15:12:17Z")

</div>

Hi, I just found out that in the following example, sampling from a Distributions.Product distribution is much slower and allocates much more than implementing the sampler manually. Is there something that I’m overlookin…

---

## [GPU backend-agnostic way to create efficiently random number on the GPU](https://discourse.julialang.org/t/gpu-backend-agnostic-way-to-create-efficiently-random-number-on-the-gpu/126110)

<div class="topic-metadata">

**Author:** [@Alexander-Barth](https://discourse.julialang.org/u/Alexander-Barth)\
**Replies:** 3\
**Last updated:** [March 3, 2025, 7:44am UTC](https://discourse.julialang.org/t/gpu-backend-agnostic-way-to-create-efficiently-random-number-on-the-gpu/126110 "2025-03-03T07:44:34Z")

</div>

I am trying to make my code Flux code portable across CUDA and AMDGPU. I would like to know if there is a GPU backend-agnostic way to create efficiently random number on the GPU? AMDGPU.randn is by far the fastest, but I…

---

## [Random numbers, with MersenneTwister, not stable across major releases](https://discourse.julialang.org/t/random-numbers-with-mersennetwister-not-stable-across-major-releases/122284)

<div class="topic-metadata">

**Author:** [@leolo](https://discourse.julialang.org/u/leolo)\
**Replies:** 8\
**Last updated:** [November 7, 2024, 3:24pm UTC](https://discourse.julialang.org/t/random-numbers-with-mersennetwister-not-stable-across-major-releases/122284 "2024-11-07T15:24:13Z")

</div>

Hi, after updating to Julia 1.11, I have an issue with a random number sequence that changed. using Random rng = Random.MersenneTwister(42) v = rng.rand(10) println(v) This gives different results under 1.10.2 and 1.11…

---

## [Noise inside an activation function in DifferentialEquations.jl](https://discourse.julialang.org/t/noise-inside-an-activation-function-in-differentialequations-jl/118219)

<div class="topic-metadata">

**Author:** [@duodenum](https://discourse.julialang.org/u/duodenum)\
**Replies:** 2\
**Last updated:** [August 18, 2024, 3:19am UTC](https://discourse.julialang.org/t/noise-inside-an-activation-function-in-differentialequations-jl/118219 "2024-08-18T03:19:13Z")

</div>

Hello, I am interested in solving Wilson - Cowan equations (or in general, a differential equation where noise is not multiplicative or additive per se, but put inside an activation function). For example: \\frac{dx}{dt…

---

## [Why are \`seed!\` and \`default\_rng\` not public?](https://discourse.julialang.org/t/why-are-seed-and-default-rng-not-public/117125)

<div class="topic-metadata">

**Author:** [@GHTaarn](https://discourse.julialang.org/u/GHTaarn)\
**Replies:** 1\
**Last updated:** [July 17, 2024, 6:51am UTC](https://discourse.julialang.org/t/why-are-seed-and-default-rng-not-public/117125 "2024-07-17T06:51:29Z")

</div>

julia\> VERSION v"1.11.0-rc1" julia\> using Random julia\> Base.ispublic(Random, :seed!), Base.ispublic(Random, :default\_rng) (false, false) Does this mean that one should avoid using these functions if the code should b…

---

## [How do I create an array with random unique numbers in a specific range?](https://discourse.julialang.org/t/how-do-i-create-an-array-with-random-unique-numbers-in-a-specific-range/115901)

<div class="topic-metadata">

**Author:** [@kwellstein](https://discourse.julialang.org/u/kwellstein)\
**Replies:** 20\
**Last updated:** [June 24, 2024, 11:53am UTC](https://discourse.julialang.org/t/how-do-i-create-an-array-with-random-unique-numbers-in-a-specific-range/115901 "2024-06-24T11:53:30Z")

</div>

Hi everyone! I have been googling and spending time in stackexchange but to no avail, I hope someone on here can help me out. What I need is an array with 30 UNIQUE random integers between 1 and 40. Somehow this seems …

---

## [Random number reproducibility from Poisson distribution](https://discourse.julialang.org/t/random-number-reproducibility-from-poisson-distribution/115359)

<div class="topic-metadata">

**Author:** [@mgp](https://discourse.julialang.org/u/mgp)\
**Replies:** 2\
**Last updated:** [June 8, 2024, 3:54pm UTC](https://discourse.julialang.org/t/random-number-reproducibility-from-poisson-distribution/115359 "2024-06-08T15:54:35Z")

</div>

I want to sample a series of random numbers from Poisson distributions, such as using Distributions, Random Random.seed!(1) rand(Poisson(10)) # 9 rand(Poisson(11)) # 12 rand(Poisson(12)) # 9 rand(Poisson(13)) # 17 …

---

## [Random sampling with rand(Uniform(0,1), n)](https://discourse.julialang.org/t/random-sampling-with-rand-uniform-0-1-n/114962)

<div class="topic-metadata">

**Author:** [@Sahil\_Khan](https://discourse.julialang.org/u/Sahil_Khan)\
**Replies:** 4\
**Last updated:** [May 30, 2024, 12:07pm UTC](https://discourse.julialang.org/t/random-sampling-with-rand-uniform-0-1-n/114962 "2024-05-30T12:07:07Z")

</div>

Hello everyone, I’m trying to collect some random samples from Uniform distribution Uniform(0,1) . What I observe is that most of values are around 10^-1 range so like 0.1, 0.3, 0.7 something like that but it rarely hi…

---

## [Rand() doesn't work with dims as tuple of Uint](https://discourse.julialang.org/t/rand-doesnt-work-with-dims-as-tuple-of-uint/112716)

<div class="topic-metadata">

**Author:** [@alex180500](https://discourse.julialang.org/u/alex180500)\
**Replies:** 5\
**Last updated:** [April 10, 2024, 6:16am UTC](https://discourse.julialang.org/t/rand-doesnt-work-with-dims-as-tuple-of-uint/112716 "2024-04-10T06:16:32Z")

</div>

I’m trying to create random numbers in a matrix given by another variable that is a UInt32. For example I have something like this: test\_uint::UInt32 = 4 rand(Float64, (test\_uint, 10)) And get the following error ERRO…

---

## [How to evaluate multivariate log normal distribution at arbitrary point?](https://discourse.julialang.org/t/how-to-evaluate-multivariate-log-normal-distribution-at-arbitrary-point/112608)

<div class="topic-metadata">

**Author:** [@structural](https://discourse.julialang.org/u/structural)\
**Replies:** 2\
**Last updated:** [April 7, 2024, 9:46am UTC](https://discourse.julialang.org/t/how-to-evaluate-multivariate-log-normal-distribution-at-arbitrary-point/112608 "2024-04-07T09:46:47Z")

</div>

Suppose I have the following distribution over two variables dist = MvLogNormal(mean\_a\_b, cov\_a\_b) Suppose h is an array of dimension 1000\\times 2. For each row of array h, the first entry represents the rank of the …

---

## [True random numbers](https://discourse.julialang.org/t/true-random-numbers/111593)

<div class="topic-metadata">

**Author:** [@neophytedave](https://discourse.julialang.org/u/neophytedave)\
**Replies:** 13\
**Last updated:** [March 16, 2024, 2:15pm UTC](https://discourse.julialang.org/t/true-random-numbers/111593 "2024-03-16T14:15:36Z")

</div>

I understand that Julia produces PRNs. (Pseudo Random Numbers). The website (www.random.org) advertises itself as producing true random numbers. I can understand that for testing purposes PRNs may be desired, but once …

---

## [Random seed initialization with splitmix](https://discourse.julialang.org/t/random-seed-initialization-with-splitmix/110426)

<div class="topic-metadata">

**Author:** [@Enlil50](https://discourse.julialang.org/u/Enlil50)\
**Replies:** 6\
**Last updated:** [February 21, 2024, 7:02pm UTC](https://discourse.julialang.org/t/random-seed-initialization-with-splitmix/110426 "2024-02-21T19:02:16Z")

</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?

---

## [Random number generation](https://discourse.julialang.org/t/random-number-generation/110010)

<div class="topic-metadata">

**Author:** [@math\_opt](https://discourse.julialang.org/u/math_opt)\
**Replies:** 19\
**Last updated:** [February 10, 2024, 10:42pm UTC](https://discourse.julialang.org/t/random-number-generation/110010 "2024-02-10T22:42:48Z")

</div>

Why do I get different result when I run the rand command twice with the same seed in the Julia REPL? using Random using Distributions rng = MersenneTwister(1234) rand(rng) # outputs 0.5908446386657102 #run again ran…

---

## [Can rand generate random vectors with custom type entries?](https://discourse.julialang.org/t/can-rand-generate-random-vectors-with-custom-type-entries/107028)

<div class="topic-metadata">

**Author:** [@matthias314](https://discourse.julialang.org/u/matthias314)\
**Replies:** 5\
**Last updated:** [December 2, 2023, 4:41am UTC](https://discourse.julialang.org/t/can-rand-generate-random-vectors-with-custom-type-entries/107028 "2023-12-02T04:41:09Z")

</div>

I’m trying to understand how to implement rand for custom types. After looking at the documentation, I’ve come up with the following: using Random struct A{T} x::T end Random.rand(rng::AbstractRNG, ::Type{A{T}}) w…

---

## [Static array with uniform distribution](https://discourse.julialang.org/t/static-array-with-uniform-distribution/106961)

<div class="topic-metadata">

**Author:** [@sand](https://discourse.julialang.org/u/sand)\
**Replies:** 2\
**Last updated:** [November 30, 2023, 8:11pm UTC](https://discourse.julialang.org/t/static-array-with-uniform-distribution/106961 "2023-11-30T20:11:50Z")

</div>

Hello, I would like to know how to generate a static array with a uniform distribution (-2, 2). Here is an example: using StaticArrays using Distributions @SVector(randn(5)) # works rand(Uniform(-2, 2), 5) # w…

---

## [Custom Sampler with multiple parameters](https://discourse.julialang.org/t/custom-sampler-with-multiple-parameters/106446)

<div class="topic-metadata">

**Author:** [@oliviermilla](https://discourse.julialang.org/u/oliviermilla)\
**Replies:** 4\
**Last updated:** [November 23, 2023, 1:37pm UTC](https://discourse.julialang.org/t/custom-sampler-with-multiple-parameters/106446 "2023-11-23T13:37:15Z")

</div>

Hello, with the following structures I’d like to do this: struct A a::Float64 b::Float64 end struct B x::Float64 end b = B(32.5) res = rand(A, b, 3) # Vector of 3 A with the computation of the random 3 A fact…

---

## [Output distribution of rand(Float32) and rand(Float64), thread 2](https://discourse.julialang.org/t/output-distribution-of-rand-float32-and-rand-float64-thread-2/105184)

<div class="topic-metadata">

**Author:** [@foobar\_lv2](https://discourse.julialang.org/u/foobar_lv2)\
**Replies:** 437\
**Last updated:** [November 19, 2023, 12:45pm UTC](https://discourse.julialang.org/t/output-distribution-of-rand-float32-and-rand-float64-thread-2/105184 "2023-11-19T12:45:38Z")

</div>

A recent hackernews post lead me to necro https://discourse.julialang.org/t/output-distribution-of-rand/12192. If we want to reopen that can, I think a new thread is in order. Summary rand(), and much more acutely rand(…

---

## [QMC vs rand](https://discourse.julialang.org/t/qmc-vs-rand/106195)

<div class="topic-metadata">

**Author:** [@tchebycheff](https://discourse.julialang.org/u/tchebycheff)\
**Replies:** 12\
**Last updated:** [November 16, 2023, 5:28am UTC](https://discourse.julialang.org/t/qmc-vs-rand/106195 "2023-11-16T05:28:19Z")

</div>

X\_t is a d-dimensional geometric Brownian process and Y\_t = \\min\_i X\_t^{(i)}. My objective is to simulate paths of Y\_t at t=\\Delta, 2\\Delta, ..., M\\Delta. There are significant differences in E(Y\_t) estimates from QMC/S…

---

## [Generating Float32 uniform random numbers with Distributions.jl](https://discourse.julialang.org/t/generating-float32-uniform-random-numbers-with-distributions-jl/63889)

<div class="topic-metadata">

**Author:** [@bad\_at\_math](https://discourse.julialang.org/u/bad_at_math)\
**Replies:** 2\
**Last updated:** [November 6, 2023, 2:32pm UTC](https://discourse.julialang.org/t/generating-float32-uniform-random-numbers-with-distributions-jl/63889 "2023-11-06T14:32:43Z")

</div>

I can define and sample from a uniform distribution with Float32 bounds as follows: using Distributions dist = Uniform{Float32}(-1.0f0, 1.0f0) x = rand(dist) However, the x here has type Float64, not Float32. Is there…

[Next page](https://discourse.julialang.org/tag/random/637.md?match_all_tags=true&page=1&tags%5B%5D=random)
