Gu Wu
Gu Wu

Reputation: 41

In J, how do we generate a list of numbers that come from a normal distribution with a specified mean and variance

In J, I know that we can generate a list of uniform random numbers, and use some sort of inverse function to have a list of normal distribution number. But is there a quick way to achieve this?

Upvotes: 1

Views: 164

Answers (1)

Igor Zhuravlov
Igor Zhuravlov

Reputation: 426

How to generate, say, a 3*4-matrix B with elements b distributed as b ~ N(5,0.9^2)

A way #1

load 'stats/distribs'
B=. 5 0.9 rnorm 3 4

A way #2

load 'math/mt'

NB. real b ~ N(5,0.9^2)
B=. 5 0.9 randnf_mt_ 3 4

NB. complex b ~ N(5+i*6,0.9^2)
B=. 5j6 0.9 randnc_mt_ 3 4

NB. quaternion b ~ N(5+i*6+j*7+k*8,0.9^2)
B=. 5j6 7j8 0.9 randnq_mt_ 3 4

Both uses Box-Muller approach.

Upvotes: 3

Related Questions