范围内的随机数

Aar*_*ron 8 delphi random numbers range

这是Delphi(确切地说是7).如何在特定范围内生成随机数?与random.randint(1,6)Python 类似.我正在尝试模拟掷骰子.另一种选择是以某种方式排除0.

目前我有:

Randomize;
Roll := Random(7);
Label3.Caption := IntToStr(Roll);
Run Code Online (Sandbox Code Playgroud)

And*_*and 22

您可以使用

RandomRange(1, 7)
Run Code Online (Sandbox Code Playgroud)

这将从集{1,2,3,4,5,6}中返回一个随机整数.

(uses Math)

[顺便说一下,'以某种方式'排除零是微不足道的.做吧Random(6) + 1.]