+ Reply to Thread
Results 1 to 5 of 5

Thread: How do I program a random generator?

  1. #1
    Newbie eddiewillers is an unknown quantity at this point
    Join Date
    Jul 2007
    Posts
    1

    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. #2
    Retired v0id is a glorious beacon of light v0id is a glorious beacon of light v0id is a glorious beacon of light v0id is a glorious beacon of light v0id is a glorious beacon of light v0id is a glorious beacon of light
    Join Date
    Apr 2007
    Posts
    2,978
    Blog Entries
    3
    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()

  3. #3
    Super Moderator WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther's Avatar
    Join Date
    Jul 2006
    Age
    36
    Posts
    11,680
    Blog Entries
    57
    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

  4. #4
    Programmer CygnetGames is an unknown quantity at this point CygnetGames's Avatar
    Join Date
    May 2007
    Location
    York, England
    Posts
    118
    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)];

  5. #5
    Programming Expert Crane is on a distinguished road Crane's Avatar
    Join Date
    Nov 2005
    Posts
    399
    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

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

     

Similar Threads

  1. Need help w/ word count program (ASAP)
    By siren in forum C and C++
    Replies: 3
    Last Post: 09-11-2009, 07:17 AM
  2. Random Generator of Unequal Numbers
    By Paradine in forum PHP Tutorials
    Replies: 0
    Last Post: 08-26-2007, 02:11 PM
  3. Floating Point random number generator
    By Paradine in forum PHP Tutorials
    Replies: 0
    Last Post: 08-26-2007, 02:09 PM
  4. The latest program i wrote!!
    By A.N.H in forum Java Help
    Replies: 1
    Last Post: 04-30-2007, 02:36 PM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

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