Lost Password?


Go Back   CodeCall Programming Forum > Software Development > General Programming

General Programming Non language specific, Assembly, Linux/Unix, Mac 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, 11:58 AM
eddiewillers eddiewillers is offline
Newbie
 
Join Date: Jul 2007
Posts: 1
Rep Power: 0
eddiewillers is on a distinguished road
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

Sponsored Links
  #2 (permalink)  
Old 07-18-2007, 12:32 PM
v0id's Avatar   
v0id v0id is offline
Retired
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,635
Last Blog:
CherryPy(thon)
Rep Power: 28
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
Send a message via MSN to v0id
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()
__________________
05-03-2007 - 11-13-2008
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-18-2007, 12:59 PM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 3,278
Last Blog:
wxWidgets is NOT code ...
Rep Power: 36
WingedPanther is a name known to allWingedPanther is a name known to allWingedPanther is a name known to allWingedPanther is a name known to allWingedPanther is a name known to allWingedPanther is a name known to all
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 07-24-2007, 11:22 AM
CygnetGames's Avatar   
CygnetGames CygnetGames is offline
Programmer
 
Join Date: May 2007
Location: York, England
Posts: 113
Rep Power: 6
CygnetGames is on a distinguished road
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, 03:26 PM
Crane's Avatar   
Crane Crane is offline
Programming Expert
 
Join Date: Nov 2005
Posts: 399
Rep Power: 14
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

Sponsored Links
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
Forum Jump

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


All times are GMT -5. The time now is 06:03 PM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 98%

Ads