Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a random number in pascal?

Tags:

pascal

I want to get a random number in pascal from between a range. Basically something like this:

r = random(100,200);

The above code would then have a random number between 100 and 200.

Any ideas?

The built in pascal function only lets you get a number from between 0-your range, while i need to specify the minimum number to return

like image 463
Ali Avatar asked Feb 11 '11 05:02

Ali


2 Answers

As already pointed out, you should use

myrandomnumber := random(span) + basenumber;

However, to get better quality random numbers, you should call

randomize();

once, on start of your application, to initialize the random number generator.

like image 183
Tuncay Göncüoğlu Avatar answered Nov 11 '22 15:11

Tuncay Göncüoğlu


Just get a random number with the correct range (ie 100 to 200 would be range 100) then add the starting value to it

So: random(100) + 100 for your example

like image 13
Ralph Avatar answered Nov 11 '22 17:11

Ralph