小编Del*_*lta的帖子

如何获得随机的0和1数字

所以基本上为了好玩,我试图生成一列数字(7位只有0和1)我的代码很短:

a = rand(0000000-1111111)
b = 220
a1 = rand(0000000-1111111)
a2 = rand(0000000-1111111)
a3 = rand(0000000-1111111)
a4 = rand(0000000-1111111)
a5 = rand(0000000-1111111)

while b !=0
  puts a
  puts a2
  puts a3
  puts a4
  puts a5
end
Run Code Online (Sandbox Code Playgroud)

我的问题是,不是生成0和1的随机列,而是使用所有数字.

ruby random loops

5
推荐指数
2
解决办法
2637
查看次数

标签 统计

loops ×1

random ×1

ruby ×1