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

Username:   Password: 
 RegisterRegister   
 Generating Random Numbers!
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
B-747




PostPosted: Tue Mar 15, 2005 9:40 pm   Post subject: Generating Random Numbers!

Guys i am in desperate need of a a short code that will generate three randome numbers (From 1-9) and Three random Alphabats!
Please Help me!!! I'd appreciate the help! Sad
Sponsor
Sponsor
Sponsor
sponsor
McKenzie




PostPosted: Tue Mar 15, 2005 10:03 pm   Post subject: (No subject)

There are a few ways. I prefer to use Math.random(). Math is in java.lang so you don't need to import it and random is a static method so you don't need an instance of the class. It returns a double between 0.0 and 1.0. To get an integer from 1-6 you would use:
java:
code:
die = (int)(Math.random() * 6 + 1)
B-747




PostPosted: Wed Mar 16, 2005 12:54 am   Post subject: (No subject)

Surprised Well, thanks Mackenzie, I appreciate ur help. U think u can tell me how to generate random Alphabets? I could really use that!
McKenzie




PostPosted: Wed Mar 16, 2005 11:55 am   Post subject: (No subject)

Why does everone spell my name wrong?

In Java a character is just it's ascii value. So for example:
code:
System.out.println((char)67);

will print C
So now just randomly generate your numbers in the ascii range you need:
A-Z == 65-90
a-z == 97-122
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: