We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › randomly select a word
Page Index Toggle Pages: 1
randomly select a word (Read 661 times)
randomly select a word
Jan 19th, 2010, 6:01am
 
Hey guys,

I have written a program that creates a piece of artwork using randomly placed lines and randomly selected colours. Now, i want the program to select a random word from a list (possibly a list in a txt doc) and print it to the screen. I know how to select a random word from a selection but i want the list of words to choose from to be at least 100 so it would be easier if i could get the program to select one from a pre-made list.

any ideas?
Re: randomly select a word
Reply #1 - Jan 19th, 2010, 6:19am
 
Can't you just put the words into an array (easy enough to do from a textfile using loadStrings (and split() if necessary)) and then use:

Code:
String randomWord = wordsArray[(int)random(wordsArray.length)]; 

Re: randomly select a word
Reply #2 - Jan 19th, 2010, 6:28am
 
ok. silly question then how would i create an array from the words?
Re: randomly select a word
Reply #3 - Jan 19th, 2010, 6:42am
 
its ok iv got it i think...
Page Index Toggle Pages: 1