Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

How to generate random string or character from arrays?

  Asked By: Nichole    Date: May 22    Category: Java    Views: 2472
  

How can I generate random characters or strings from a list of array
and the result is a randomly created sentence using the two arrays?
For example I have a list of array called list1=
{"Crazy","Funny","Stupid","Lazy"} and list2=
{"John","monkey","Tina","boy"}. I want to generate an output
sentence in the order list1 list2,for example Crazy Tina or Funny
monkey etc randomly.Thank you in advance.Hope somebody can help.

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Julio Morgan     Answered On: May 22

something like list1[(Math.rand()*list1.length)+1) should pick a random
element from the list1 String[]

 
Answer #2    Answered By: Opal Alexander     Answered On: May 22

Create one or two random  numbers between 0 and 3
and use them to fetch the entries from array

 
Didn't find what you were looking for? Find more on How to generate random string or character from arrays? Or get search suggestion and latest updates.




Tagged: