Author 
Message 
DJ

Posted: Thu Aug 07, 2003 3:35 pm Post subject: random real numbers 


i wanna make random real numbers between a certain range.
i wanna make these real numbers prices, so ineed a decimal cutoff
how? 





Sponsor Sponsor



poly

Posted: Thu Aug 07, 2003 5:27 pm Post subject: (No subject) 


ooops what I posted here was for integers, sorry! 





AsianSensation

Posted: Thu Aug 07, 2003 7:04 pm Post subject: (No subject) 


Rand.Real
it generates a real number between 0 and 1
then just multiply it by a multiplier if you want bigger numbers to be generated
for example, you want a real number between 0 and 100
num:=Rand.Real * 100 





DJ

Posted: Thu Aug 07, 2003 9:54 pm Post subject: (No subject) 


but if i want a random real number between 1 and 100 and with 2 decimal places?
i dunno how to use the round function, the help thing dont help 





kmd10

Posted: Thu Aug 07, 2003 10:00 pm Post subject: (No subject) 


ok .. use Rand.Real, giving you a number between 0 and 1.
then use a multiplier.
then multiply it by 100.
then use round(n).
then divide by 100, and throw in your dollar sign.
code: 
var num : real
var int_num : int
var multiplier : int := 100 % now it's a number from 0 to 100.
num := Rand.Real * multiplier * 100
int_num := round(num)
num := int_num / 100

you could shorten this, but it's to show you what i mean.
code: 
var multiplier : int := 10000
var num : real := (round(Rand.Real * multiplier)) / 100

and then after that, you'd need to do your check to add necessary zeroes. but that shouldn't be a problem. 





DJ

Posted: Sun Aug 10, 2003 10:03 pm Post subject: (No subject) 


wow and then some that was a good answer 





Namis

Posted: Thu Sep 11, 2003 3:06 pm Post subject: Rand.Real 


Couldnt you just use
randint(X,X) ??? 





krishon

Posted: Thu Sep 11, 2003 4:25 pm Post subject: (No subject) 


i think that's just for integers.... 





Sponsor Sponsor



Tony

Posted: Thu Sep 11, 2003 4:44 pm Post subject: (No subject) 


it is... Rand.Int() actually uses Rand.Real() function inside itself to come up with an int. 
Tony's programming blog. DWITE  a programming contest. 




