Computer Science Canada

Generating Random Numbers!

Author:  B-747 [ 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

Author:  McKenzie [ Tue Mar 15, 2005 10:03 pm ]
Post 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)

Author:  B-747 [ Wed Mar 16, 2005 12:54 am ]
Post 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!

Author:  McKenzie [ Wed Mar 16, 2005 11:55 am ]
Post 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


: