Page 1 of 1
[Implemented] Random with max, min and type
Posted: Sun Feb 22, 2004 12:44 am
by techjunkie
It would be nice with a random function where you could specify max and min. It also would be nice if you could use float as a parameter or you could specify what type you want in return.
For example...
Result.f = Random(0.4, 1.2)
or
Result.w = Random(600, 800)
I'm sure someone else must have come with the same request here before...
Posted: Sun Feb 22, 2004 1:54 am
by WolfgangS
Hi
In the meantime you can use this:
Code: Select all
hans.f=Random(8)/10+0.4
Debug hans.f
Debug SizeOf(hans)
sepp.w=Random(200)+600
Debug sepp.w
Debug SizeOf(sepp)
MFG
WolfgangS
Posted: Sun Feb 22, 2004 10:22 am
by Kris_a
It's better than C's rand() at least - you can't even input a 'maximum' with that

Posted: Sun Feb 22, 2004 10:25 am
by techjunkie
WolfgangS wrote:Hi
In the meantime you can use this:
Code: Select all
hans.f=Random(8)/10+0.4
Debug hans.f
Debug SizeOf(hans)
sepp.w=Random(200)+600
Debug sepp.w
Debug SizeOf(sepp)
MFG
WolfgangS
Yes - thanks... It's just what I'm doing right now... But if you want very small number it is a lot of typing. For example... If you want a random number between 0.006 and 0.008.
Code: Select all
Debug ((Random(1000) *0.002)/1000 + 0.006)
Posted: Mon Feb 23, 2004 4:28 pm
by guido
techjunkie wrote:
Yes - thanks... It's just what I'm doing right now... But if you want very small number it is a lot of typing. For example... If you want a random number between 0.006 and 0.008.
Code: Select all
Debug ((Random(1000) *0.002)/1000 + 0.006)
Have you considered to write a function for it

? I would hate to have a language bloated by stuff, which can easily be supplied using a few lines of code and doesn't look differently when looking at the high level (function call). C was divided to core language and a standard library for good reason...
Posted: Mon Feb 23, 2004 8:51 pm
by techjunkie
guido wrote:Have you considered to write a function for it

?
Of course I use a procedure, but it slow down things in critical code...
Thinking of doing it in assembler...