Hi, I need to write a random generator for company use. All I need is a site to display a random phrase from a preset list of phrases.
Does anyone already have code for it?
Thanks!
Hi, I need to write a random generator for company use. All I need is a site to display a random phrase from a preset list of phrases.
Does anyone already have code for it?
Thanks!
If you really want a good generator, the only thing you can use is mother earth. Put up some engine, that gets wind speed, and calculate from that. The wind speed is very random, and if you combines it with time, it will be even more random. Instead of wind, you could use something else, like sound, or everything else.
Another, and easier way, is to look at this:
Eternally Confuzzled - Using rand()
For what you're describing, you just need to use the random number generation provided by most languages to generate an integer, and display the corresponding phrase (possibly stored in an array).
CodeCall Blog | CodeCall Wiki | Shareware
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog
Like WingedPanter said:
Have your phrases stored in an array.
Use the random number generator provided with your language to pick an array index at random.
Display the phrase at that index.
Random number generators usualy give you a random double-precision number between 0 and 1, so you would do something like:
Code:phrase = phrase_array[(int)(random()*size_of_array)];
Odd but interesting answer.
Here is an easy way to do it in php: Generating Random Numbers using PHP
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks
Algorithms and Data Structures
Java tutorials
Algorithms Forum