![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: May 2006
Posts: 21
Rep Power: 0
![]() |
Random
How do you do random things with C++. If someone has written a dice roller or random number genorator, if they could post it here that would be great. And maybe explain it a bit. Thanks.
:banana: :banana: :banana: :banana: :banana: <<<Oh my God, it's N'Sync!!! RUN AWAY!!!
__________________
Kids, every year, more than 400,000 people die from tobacco chewing, smoking, an- MY GOD, HERE COMES A ZOMBIE PIRATE NINJA!!!!!! |
|
|
|
|
|
#2 |
|
Professional Programmer
![]() Join Date: Sep 2005
Posts: 419
Rep Power: 4
![]() |
Include <cstdlib> and make use of the srand and rand functions. Some info on how to use them can be found here.
__________________
Even if the voices aren't real, they have some pretty good ideas. |
|
|
|
|
|
#3 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
Almost anything is pseudo random, many links can be found on this forum and even more on google, like here.
N'Sync... I thought that group was dead. Justin is singing solo now isn't he?
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
|
|
#4 |
|
Programmer
Join Date: Sep 2005
Location: Oopland
Posts: 36
Rep Power: 0
![]() |
Die Roller
Like this?
// Die Roller
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
srand(time(0)); // seeds the random number generator based on the current time
int randomNumber = rand(); // generate random number
int die = (randomNumber % 6) + 1; // get a number between 1 and 6
cout << "You rolled a " << die << endl;
return 0;
}Pretty self explanatory, and a rather simplified version of a dice roller. |
|
|
|
|
|
#5 |
|
Newbie
Join Date: May 2006
Posts: 21
Rep Power: 0
![]() |
Thx for ur help, guys.
__________________
Kids, every year, more than 400,000 people die from tobacco chewing, smoking, an- MY GOD, HERE COMES A ZOMBIE PIRATE NINJA!!!!!! |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|