Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想在 ruby 中生成一个 64 位整数。我知道在 Java 中你很长,但我不确定你会如何在 Ruby 中做到这一点。另外,64位数字中有多少个字符?这是我所说的一个例子...... 123456789999。
@num = Random.rand(9000) + Random.rand(9000) + Random.rand(9000)
但我认为这是非常低效的,必须有一种更简单、更简洁的方式来做到这一点。
谢谢!
rand可以将范围作为参数:
p a = rand(2**32..2**64-1) # => 11093913376345012184 puts a.class #=> Bignum
来自文档:Bignum 对象包含 Fixnum 范围之外的整数。当整数计算会溢出 Fixnum 时,会自动创建 Bignum 对象。当涉及 Bignum 对象的计算返回适合 Fixnum 的结果时,结果将自动转换...