| | |
Random number sequences
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Dec 2006
Posts: 1,089
Reputation:
Solved Threads: 164
c++ Syntax (Toggle Plain Text)
#include <cstdlib> #include <string> inline char random_digit() { return '0' + std::rand() % 10 ; } inline std::string random_pin( std::size_t ndigits ) { std::string pin ; for( std::size_t i = 0 ; i < ndigits ; ++i ) pin += random_digit() ; return pin ; }
•
•
Join Date: Jun 2008
Posts: 10
Reputation:
Solved Threads: 0
I tried it, and recieved an error,
C++ Syntax (Toggle Plain Text)
[Linker error] undefined reference to `WinMain@16'
vijayan121 has just provided the functions, you'll have to adapt them according to your main code and use them. His functions will compile, but how do you expect them to run?!
"You know you're a computer geek when you try to shoo a fly away from the monitor screen with your cursor. That just happened to me. It was scary." - Juuso Heimonen.
"The only truly secure computer is one buried in concrete, with the power turned off and the network cable cut." - Anonymous.
"The only truly secure computer is one buried in concrete, with the power turned off and the network cable cut." - Anonymous.
•
•
Join Date: Nov 2007
Posts: 978
Reputation:
Solved Threads: 208
•
•
•
•
I tried it, and recieved an error,
C++ Syntax (Toggle Plain Text)
[Linker error] undefined reference to `WinMain@16'
If you want to build a GUI program, then write the WinMain(...) too, see
http://msdn.microsoft.com/en-us/library/ms633559.aspx
Otherwise, start a new Win32 Console Application project, which uses the
int main() . •
•
Join Date: Jun 2008
Posts: 10
Reputation:
Solved Threads: 0
Okay, i tried something that i thought up, reading up i remembered that a 17 digit number isnt really possible in C++... so i have come up with this, however i am getting two errors, i think it has something to do with the brackets... but i cant figure anything out
errors:
C++ Syntax (Toggle Plain Text)
#include <cstdio> #include <cstdlib> #include <ctime> #include <iostream> using namespace std; int main(int nNumberofArgs, char* pszArgs[]) { srand ( (unsigned)time ( 0 ) ); const int a = rand() % 9 ; const int b = rand() % 9 ; const int c = rand() % 9 ; const int d = rand() % 9 ; const int e = rand() % 9 ; const int f = rand() % 9 ; const int g = rand() % 9 ; const int h = rand() % 9 ; const int i = rand() % 9 ; const int j = rand() % 9 ; const int k = rand() % 9 ; const int l = rand() % 9 ; const int m = rand() % 9 ; const int n = rand() % 9 ; const int o = rand() % 9 ; const int p = rand() % 9 ; const int q = rand() % 9 ; const int r = rand() % 9 ; { char transactionType; cout << "Press N to cancel, and Y to continue:\n " << endl; cin >> transactionType; if (transactionType == 'x' || transactionType == 'X') { break; } if (transactionType == 'y' || transactionType == 'y') { continue ; } } { cout << "abcdefghijklmnopqr"; } }
errors:
C++ Syntax (Toggle Plain Text)
break statement not within continue statement not within
C++ Syntax (Toggle Plain Text)
#include <cstdio> #include <cstdlib> #include <ctime> #include <iostream> using namespace std; int main ( int nNumberofArgs, char* pszArgs[] ) { srand ( ( unsigned ) time ( 0 ) ); const int a = rand() % 9 ; const int b = rand() % 9 ; const int c = rand() % 9 ; const int d = rand() % 9 ; const int e = rand() % 9 ; const int f = rand() % 9 ; const int g = rand() % 9 ; const int h = rand() % 9 ; const int i = rand() % 9 ; const int j = rand() % 9 ; const int k = rand() % 9 ; const int l = rand() % 9 ; const int m = rand() % 9 ; const int n = rand() % 9 ; const int o = rand() % 9 ; const int p = rand() % 9 ; const int q = rand() % 9 ; const int r = rand() % 9 ; { char transactionType; cout << "Press N to cancel, and Y to continue:\n " << endl; cin >> transactionType; if ( transactionType == 'x' || transactionType == 'X' ) { break; } if ( transactionType == 'y' || transactionType == 'y' ) { continue ; } } { cout << "abcdefghijklmnopqr"; } }
Most of your program doesn't make any sense. Should I elaborate or do you wanna look at a newbie tutorial?
Last edited by iamthwee; Jun 22nd, 2008 at 4:04 pm.
*Voted best profile in the world*
•
•
Join Date: Jun 2008
Posts: 10
Reputation:
Solved Threads: 0
Elaborate please =], i was trying to say that a-r are random numbers between 1 and 9, this is just a snipet of some code i already have, i an just having some problems with figuring out random numbers... i figured that if the largest variable is an unsigned, max of about 4 billion, and seing as i need a 17 digit number, i generate a number for each digit, when the person continues it prints out each digit in the end
•
•
Join Date: Apr 2008
Posts: 296
Reputation:
Solved Threads: 42
•
•
•
•
Elaborate please =], i was trying to say that a-r are random numbers between 1 and 9, this is just a snipet of some code i already have, i an just having some problems with figuring out random numbers... i figured that if the largest variable is an unsigned, max of about 4 billion, and seing as i need a 17 digit number, i generate a number for each digit, when the person continues it prints out each digit in the end
Well dear Superfat, the most effective solution for you problem has already been given by vijayan121. Unfortunately you aren't able to understand his fine function. So GOD's advice should be seriously followed.
Btw, your nice random numbers a..r never contain 9, got it?
krs,
tesu
Last edited by tesuji; Jun 22nd, 2008 at 4:39 pm.
![]() |
Similar Threads
- Cant understand random number generation (C++)
- Pascal random numbers are not random (Pascal and Delphi)
- Confusion with arrays and sorting (C++)
- Help programming game (Pascal and Delphi)
- help with this assigment please..it's ARGENT..! (C++)
- random number generator (C++)
Other Threads in the C++ Forum
- Previous Thread: student needing guidance on final exam code
- Next Thread: storing a "word" within a sentence
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count data database delete deploy developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






