This is in Delphi (7 to be exact). How can I generate random numbers within a specific range? Similar to random.randint(1,6) in Python. I’m trying to simulate rolling dice. The other option is to somehow exclude 0.
Currently I have:
Randomize;
Roll := Random(7);
Label3.Caption := IntToStr(Roll);
You can use
which will return a random integer from the set {1, 2, 3, 4, 5, 6}.
(
uses Math)[By the way, it is trivial to ‘somehow’ exclude zero. Just do
Random(6) + 1.]