random selection.
I've been looking at the rnadom function but cant figure it out. I have three strings lets say:
String s1 = "something1";
String s2 = "something2";
String s3 = "something3";
well i cant figure out how i could randomly select one. Random(); doesnt look like it would work. And thats the only random way. I'm use to php coding were u do Random(1, 5) and it would select a random value between the two. I could get it in php but cant excatly understand the java random procedyre. Links to anything like this or a tutorial on this or a code snipplet o anything of help would be appricated.
# 10
> > String[] strings = new String[3]
> strings[0] = s1;
> //add the rest
> ...
> String random = strings[(int)(Math.random()*2)];
>
>
> something like that
> add them to an array
Don't use Math.random, use java.util.Random
http://java.sun.com/docs/books/effective/excursion-random.html
# 11
> while you are at trying it, try to give me the dukes
>
> to everyone else who replied to this thread i have
> this to say:
> SUCKAS!
Except that your example uses a different class and is more complicated than needs be and it is brittle.
This is better.
String[] strings = new String[3]
strings[0] = s1;
//add the rest
...
Random r = new Random();
String random = strings[r.nextInt(strings.length)];