Computer Science Canada random real numbers |
Author: | DJ [ 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? |
Author: | poly [ Thu Aug 07, 2003 5:27 pm ] |
Post subject: | |
ooops what I posted here was for integers, sorry! |
Author: | AsianSensation [ Thu Aug 07, 2003 7:04 pm ] |
Post 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 |
Author: | DJ [ Thu Aug 07, 2003 9:54 pm ] |
Post 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 |
Author: | kmd-10 [ Thu Aug 07, 2003 10:00 pm ] | ||||
Post 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.
you could shorten this, but it's to show you what i mean.
and then after that, you'd need to do your check to add necessary zeroes. but that shouldn't be a problem. |
Author: | DJ [ Sun Aug 10, 2003 10:03 pm ] |
Post subject: | |
wow and then some that was a good answer |
Author: | Namis [ Thu Sep 11, 2003 3:06 pm ] |
Post subject: | Rand.Real |
Couldnt you just use randint(X,X) ??? |
Author: | krishon [ Thu Sep 11, 2003 4:25 pm ] |
Post subject: | |
i think that's just for integers.... |
Author: | Tony [ Thu Sep 11, 2003 4:44 pm ] |
Post subject: | |
it is... Rand.Int() actually uses Rand.Real() function inside itself to come up with an int. |