I need a random Integer < 7500 and > 2800. This is the way I doing it now but was wondering if there isn't a better way?Simplify the problem: Suppose, you call Random(4). This will return the numbers 0, 1, 2 or 3. Now add 10, i.e. Random(4)+10 - you will get numbers 10, 11, 12, or 13. In general, when you need random integers from the interval [n1..n2] you put the difference of the range limits plus 1 into the argument of Random (--> Random(n2-n1+1)), and you must add the lower limit of the interval (--> n1 + Random(n2-n1+1)). The "plus 1" is required because Random(n) returns values from 0 to n-1.
Seems I read somewhere you have to call x := Random() to initialize the generator.No, a single call to Randomize initialises the generator (perhaps in your main form's OnCreate handler).
So if I'm reading you right it would be Random(7500 - (2800 + 1)). I'll give it a try.
Random(n2-n1+1))
And the simple solution of JLWests question isAgain, not exactly. He is requesting >2800, but your smallest random number would be equal to 2800. And the upper limit is requested as "< 7500", i.e. the largest number should be equal 7499 - your largest number, however, is 7498 because the argument of the random function is never returned as a result.
x0 := random (7500 - 2800 -1) + 2800;