
-----------------------------------
B-747
Tue Mar 15, 2005 9:40 pm

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!  :(

-----------------------------------
McKenzie
Tue Mar 15, 2005 10:03 pm


-----------------------------------
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:die = (int)(Math.random() * 6 + 1)

-----------------------------------
B-747
Wed Mar 16, 2005 12:54 am


-----------------------------------
:o Well, thanks Mackenzie, I appreciate ur help. U think u can tell me how to generate random Alphabets? I could really use that!

-----------------------------------
McKenzie
Wed Mar 16, 2005 11:55 am


-----------------------------------
Why does everone spell my name wrong?

In Java a character is just it's ascii value. So for example:
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
