Generate a random number from normal distribution in J

Viewed 111

In J programming: I know how to get a linear random number.

? 5#10
1 3 3 4 7

But how to get a random number from normal distribution, e.g. N(0,1)? Thanks!

2 Answers

I think you're looking for normalrand in the stats package:

   load 'stats'
   normalrand 5
_0.514477 1.23645 _0.353373 _0.522193 1.23505

See also the stats/distribs addon

   load 'stats/distrib'
   rnorm 4
_0.486091 _0.339021 1.50653 0.19308
   10 2 rnorm 4    NB. from distribution N(10,2)
10.0588 11.0472 13.6208 8.78888
Related