Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
random real numbers
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?

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
kmd-10

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....

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.
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 9 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: