|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
||||
|
||||
|
How do I get a program to return a random Symbol (%*&+-) etc. and/or numbers from a given set (2 4 6 8) to a user?
I'm using Visual c++ on XP. |
|
#2
|
|||
|
|||
|
...by getting a random number over the range of the array index values containing the symbols.
#include <cstdlib> #include <ctime> //seed the random number generator with time() function srand(static_cast<unsigned>( time(0))); //generate random number from 0 to count-1 random_number=random(count); //Function to generate a random integer 0 to count -1 int random(int count) { return static_cast<int>((count*static_cast<long>(rand()))/(RAND_MAX+1)); } From Ivor Horton's Beginning C++ 6. Last edited by 7stud : March 3rd, 2003 at 03:17 AM. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > return random symbol &\ or number? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|