Code to generate Gaussian (normally distributed) random numbers in Ruby

后端 未结 4 722
夕颜
夕颜 2021-02-01 03:32

What is some code to generate normally distributed random numbers in ruby?

(Note: I answered my own question, but I\'ll wait a few days before accepting to see if anyone

4条回答
  •  迷失自我
    2021-02-01 04:03

    Another option, this one using the distribution gem, written by one of the SciRuby fellows.

    It is a little simpler to use, I think.

    require 'distribution'
    normal = Distribution::Normal.rng(1)
    norm_distribution = 1_000.times.map {normal.call}
    

提交回复
热议问题