Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 RAndomizing Numbers
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
noobprogrammer123




PostPosted: Tue Mar 23, 2004 7:40 am   Post subject: RAndomizing Numbers

I need a little help with randomizing numbers, is there any way to set a limit to the numbers such as between 1 and 10
Sponsor
Sponsor
Sponsor
sponsor
TheZsterBunny




PostPosted: Tue Mar 23, 2004 8:01 am   Post subject: (No subject)

by number I assume you mean integer.

if you are assigning to a variable, there are 2 ways to do it.

var numbr : int
1) randint(numbr,1,10)
or
2) numbr := Rand.Int(1,10)

If you are doing a calculation and do not need to store the number, I recommend using the second option.

If you did not mean integer then you can do this.

var numbr2 : real
numbr2 := Rand.Real*Rand.Int(1,10)


The way these rand functions work is like this

randint (numbr,1,10)

number is your assigning variable
1 is your minimum number
10 is your maximum number

rand or Rand.Real returns a real number between 0 and 1 (some random decimal)

-bunny
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: