-
October 13th, 2003, 03:04 AM
#1
java random function
Hello guys,
I want to know how i can generate a random value in java, and which package will be included,
for example i want to add 4 random values
int i=0;
i+=function();
and second one how i can convert a string into capital latters in java.
thanks in advance.
PUNJABIAN263
PUNJABIAN263
-
October 13th, 2003, 04:49 AM
#2
Live as if you were to die tomorrow. Learn as if you were to live forever.
-
October 13th, 2003, 10:48 PM
#3
thanks
Hello ArchAngle,
Thanks for this help, I will check it.
PUNJABIAN263
***GOD HELPS THOSE WHO HELP THEMSELVES***
PUNJABIAN263
-
October 13th, 2003, 11:37 PM
#4
import java.util.Random;
Random randGen = new Random();
What you do next depends on the type of random numbers you wish to generate; two possibilities are:
int myInt;
myInt = randGen.nextInt();
float myFloat;
myFloat = randGen.nextFloat();
----------------------------------------------------
String myString = "Hi punjabian263!";
String myUpString = myString.toUpperCase();
-
October 15th, 2003, 11:11 AM
#5
a fast and dirty approach:
Math.random() generates a number between 0.000 and 1.000
so for a random number between 0 and 1000:
int randomInt = Math.random() * 1000
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|