如何在 Eiffel 中的两个值之间生成一个随机整数?
How to generate a random Integer between two values in Eiffel?
我想模拟掷骰子功能。但是,我没有得到我的期望。我想得到一个 Dice ,其值范围从 1 到 6,包括(dice)。
我试图在 Eiffel 文档中找到它,但是很难做到。
以下代码打印 10 个连续滚动的值:
local
r: RANDOM
do
across
1 |..| 10 as i
from
create r.set_seed (...) -- ... is the initial "seed"
r.start
loop
io.put_integer (r.item \ 6 + 1)
io.put_new_line
r.forth
end
end
我想模拟掷骰子功能。但是,我没有得到我的期望。我想得到一个 Dice ,其值范围从 1 到 6,包括(dice)。
我试图在 Eiffel 文档中找到它,但是很难做到。
以下代码打印 10 个连续滚动的值:
local
r: RANDOM
do
across
1 |..| 10 as i
from
create r.set_seed (...) -- ... is the initial "seed"
r.start
loop
io.put_integer (r.item \ 6 + 1)
io.put_new_line
r.forth
end
end