how to create a random char from a string

say that I have a very long string, say (1000) words and I want to create 2 random string from that long string, is this how I would do it using the Math.random?

where seed is the two random string that I take from the long string and book is the long string

for (int i = 0; i < 2; i++){

seed += book.charAt((int) (Math.random() * (book.length()-1)));

}

[539 byte] By [aditya15417a] at [2007-11-26 17:56:22]
# 1
What? I don't understand what you are trying to do.Kaj
kajbja at 2007-7-9 5:09:33 > top of Java-index,Java Essentials,Java Programming...
# 2

Say I have a string called book which is:

book = " I really love this java forum, it helps me a lot in programming";

and I have another string called seed, which can be

seed = "oh";

seed = "mi";

seed is a string that contains two character generated randomly from the string book. that's what I mean

aditya15417a at 2007-7-9 5:09:33 > top of Java-index,Java Essentials,Java Programming...
# 3
What you have posted is slow but you will probably notice it since you only want to characters. The code should work, but I think that your "algorithm" can't return the last character.Kaj
kajbja at 2007-7-9 5:09:33 > top of Java-index,Java Essentials,Java Programming...
# 4
so I should then use <= 2 if I want to return the last one also?
aditya15417a at 2007-7-9 5:09:33 > top of Java-index,Java Essentials,Java Programming...
# 5
> so I should then use <= 2 if I want to return the> last one also?No, I think you should remove -1Random will never return 1.Kaj
kajbja at 2007-7-9 5:09:33 > top of Java-index,Java Essentials,Java Programming...