Closed Thread
Results 1 to 5 of 5

Thread: How do I program a random generator?

  1. #1
    eddiewillers is offline Newbie
    Join Date
    Jul 2007
    Posts
    1
    Rep Power
    0

    How do I program a random generator?

    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!

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    v0id is offline Retired
    Join Date
    Apr 2007
    Posts
    2,937
    Blog Entries
    3
    Rep Power
    42
    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()

  4. #3
    Join Date
    Jul 2006
    Posts
    16,478
    Blog Entries
    75
    Rep Power
    143
    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).
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  5. #4
    CygnetGames's Avatar
    CygnetGames is offline Programmer
    Join Date
    May 2007
    Location
    York, England
    Posts
    119
    Rep Power
    0
    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)];

  6. #5
    Crane's Avatar
    Crane is offline Programming Expert
    Join Date
    Nov 2005
    Posts
    398
    Rep Power
    25
    Quote Originally Posted by v0id View Post
    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()
    Odd but interesting answer.

    Here is an easy way to do it in php: Generating Random Numbers using PHP

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Java: Random Name Generator
    By Sinipull in forum Classes and Code Snippets
    Replies: 2
    Last Post: 05-05-2011, 07:26 AM
  2. Random number generator?
    By sjshacker93 in forum Visual Basic Programming
    Replies: 5
    Last Post: 09-03-2010, 09:27 PM
  3. random quote generator
    By vocalstud69 in forum C and C++
    Replies: 30
    Last Post: 09-11-2008, 06:03 PM
  4. random number generator
    By chili5 in forum JavaScript and CSS
    Replies: 4
    Last Post: 06-01-2008, 04:55 AM
  5. Random Name Generator
    By DevilsCharm in forum C and C++
    Replies: 1
    Last Post: 11-07-2007, 09:38 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts