-2
{
String[] hi = new String[5] ;  
strArray[0] = ("Hello") ;
strArray[1] = ("hola") ;
strArray[2] = ("nihao") ;
strArray[3] = ("hallo") ;
strArray[4] = ("aloha") ; 
{

How would I use a random function to choose one of the strings in the array so it's usable?

  • Dude...really? That code isn't even close to compile-ready. Google "rand". – spartygw Jan 17 '14 at 01:05
  • 3
    Use your language's random integer generating function to generate a random number in `[0,1,2,3,4]` and pick the corresponding string... – senshin Jan 17 '14 at 01:05
  • Might be Java, in that case check out http://stackoverflow.com/questions/363681/generating-random-numbers-in-a-range-with-java?rq=1 – fvu Jan 17 '14 at 01:05
  • spartygw - just one part of my code, don't worry haha. – user3199471 Jan 17 '14 at 01:21

1 Answers1

2

IF this is java you could use

String[] hi = new String[] { "Hello", "Hola", "Nihao" };
Random rand = new Random();
System.out.println(hi[rand.nextInt(hi.length)]);
takendarkk
  • 3,347
  • 8
  • 25
  • 37