im having trouble creating a random number generator (like say a dice rolling game) if anyone could possibly show me some code for a random number generator that would be greatly appriciated :mrgreen:
trevs234
0
Newbie Poster
Recommended Answers
Jump to PostShow us what you have. You using rand()?
Jump to PostSimple solution:
Randomize(); //Required in Borland C++ //Generate a random number between 1 and 6 int random_number = (rand() % 6) + 1;
Andi
Jump to Post>> Randomize(); //Required in Borland C++
How about srand instead? That's available everywhere:#include <cstdlib> #include <ctime> #include <iostream> int main() { std::srand(static_cast<unsigned>(std::time(0))); // Generate 10 rolls of a 6 sided die for (int i = 0; i < 10; i++) std::cout << std::rand() % 6 + …
All 11 Replies
winbatch
7
Posting Pro in Training
trevs234
0
Newbie Poster
Rotak
1
Newbie Poster
Dogtree
23
Posting Whiz in Training
peter_budo
2,532
Code tags enforcer
Team Colleague
Featured Poster
trevs234
0
Newbie Poster
feda
0
Newbie Poster
TH 113
-1
Newbie Poster
jonsca
commented:
Don't bump old threads, make your own
-1
WaltP
2,905
Posting Sage w/ dash of thyme
Team Colleague
Davidov
0
Newbie Poster
WaltP
2,905
Posting Sage w/ dash of thyme
Team Colleague
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.