Why does the rand() return always the same number?

前端 未结 3 1761
没有蜡笔的小新
没有蜡笔的小新 2021-01-07 16:07

I am using

rand(200)

in my Rails application. When I run it in console it always returns random number, but if I use it in appl

3条回答
  •  南笙
    南笙 (楼主)
    2021-01-07 16:13

    Try Random.rand(). For example

    Random.rand(200)
    

    Or if you're working with an array you could use sample.

    [*1..200].sample
    

提交回复
热议问题