Connect with Facebook Lost Password?


Go Back   CodeCall Programming Forum > Software Development > General Programming

General Programming Non language specific and anything not covered in other topics. Talk about Programming Theory here.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-18-2007, 10:58 AM
Newbie
 
Join Date: Jul 2007
Posts: 1
Rep Power: 0
eddiewillers is an unknown quantity at this point
Default 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!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 07-18-2007, 11:32 AM
Retired
 
Join Date: Apr 2007
Posts: 2,975
Blog Entries: 3
Rep Power: 33
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Default

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()
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-18-2007, 11:59 AM
WingedPanther's Avatar   
Super Moderator
 
Join Date: Jul 2006
Age: 36
Posts: 8,079
Blog Entries: 48
Rep Power: 20
WingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to behold
Default

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 | Linux Forum
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 07-24-2007, 10:22 AM
CygnetGames's Avatar   
Programmer
 
Join Date: May 2007
Location: York, England
Posts: 113
Rep Power: 0
CygnetGames is an unknown quantity at this point
Default

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)];
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 07-24-2007, 02:26 PM
Crane's Avatar   
Programming Expert
 
Join Date: Nov 2005
Posts: 399
Rep Power: 16
Crane is on a distinguished road
Default

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Random Generator of Unequal Numbers Paradine PHP Tutorials 0 08-26-2007 02:11 PM
Floating Point random number generator Paradine PHP Tutorials 0 08-26-2007 02:09 PM
The latest program i wrote!! A.N.H Java Help 1 04-30-2007 02:36 PM
Need help w/ word count program (ASAP) siren C and C++ 1 04-23-2007 08:14 AM


All times are GMT -5. The time now is 09:24 PM.

Freelance Jobs

XML/XSL: Need code for Book with Chapers using XML
Create an XML file for a book of your creation, and a basic CSS file that will format it to display ...
Earn: $40.00


C++/C: Simple firework cue sequencer
What I require is a rework of a simple cue sequencer. I have a piece of hardware (an Arduino boar...
Earn: $50.00


HTML/XHTML: Menu Rework - ASCIIBin
I'm placing this in the HTML/XHTML section of the Freelance site but you are not limited to HTML. Wh...
Earn: $20.00



CodeCall Goal

Goal #1: 1,000 Blogs
Goal #2: 1,000 Wiki Pages
Goal #3: 300,000 Posts
Goal #4: 20,000 Threads
Done: 30%, 23%, 55%, 75%

Ads