# How to generate white noise?

**URL:** <https://discourse.julialang.org/t/how-to-generate-white-noise/101673>\
**Category:** Signal and Image Processing\
**Tags:** random\
**Created:** [July 16, 2023, 11:25am UTC](https://discourse.julialang.org/t/how-to-generate-white-noise/101673 "2023-07-16T11:25:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [July 16, 2023, 11:25am UTC](https://discourse.julialang.org/t/how-to-generate-white-noise/101673/1 "2023-07-16T11:25:50Z")

</div>

I need some white noise, which I then can shape to have the required spectrum using filters. But how to I generate white noise?

I could do it using `rand` or `randn`:

```julia
noise1=rand(Int(1e6)).-0.5
noise2=randn(Int(1e6))

```

I get

```julia
using Statistics
julia> var(noise1)
0.08329181864907934

julia> var(noise2)
0.9997758048382285

```

If I would multiply noise1 with a factor, would the spectrum be the same as the spectrum of noise2?

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [July 16, 2023, 12:38pm UTC](https://discourse.julialang.org/t/how-to-generate-white-noise/101673/2 "2023-07-16T12:38:24Z")

</div>

> [@ufechner7](#):
>
> If I would multiply noise1 with a factor, would the spectrum be the same as the spectrum of noise2?

Yes, the same spectrum (mean [spectral density](https://en.wikipedia.org/wiki/Spectral_density)) and even the same distribution in the Fourier domain in the limit as your signal length goes to infinity, by the [central limit theorem](https://en.wikipedia.org/wiki/Central_limit_theorem) (which just requires you to make the mean and variance the same — use `(rand() - 0.5) * √12` to get a variance of 1).
