Click here to Skip to main content
       

C / C++ / MFC

 
QuestionRandom Number Pinmemberpix_programmer25-Sep-12 20:05 
AnswerRe: Random Number Pinmemberihoecken25-Sep-12 20:38 
AnswerRe: Random Number PinmvpCPallini25-Sep-12 22:25 
AnswerRe: Random Number Pinmemberihoecken25-Sep-12 23:55 
GeneralRe: Random Number PinmvpCPallini26-Sep-12 0:28 
GeneralRe: Random Number Pinmemberihoecken26-Sep-12 0:35 
AnswerRe: Random Number Pingroup_AnsHUMAN_ 26-Sep-12 0:12 
AnswerRe: Random Number PinmemberClark Kent SuperCoder26-Sep-12 8:00 
The code is as follows : int random_number = (rand() % 6) + 1;
 
Example of use:
 

#include <cstdlib>
#include <ctime>
#include <iostream>
using namespace std ;
 

 
int main(void)
{   //seed
    srand(static_cast<unsigned>(time(0)));
 

    cout<<" \nDICE GAME\n";
 
    //Generate a random number between 1 and 6
    int random_number = (rand() % 6) + 1;
 
    cout<<" \nYou threw a ["<<random_number <<"]\n\n";
 

   return 0;
} 

AnswerOT Just curious... Pinmemberjeron126-Sep-12 8:21 
QuestionRe: OT Just curious... PinmemberDavidCrow26-Sep-12 10:52 
AnswerRe: OT Just curious... PinmvpCPallini26-Sep-12 10:55 
GeneralRe: OT Just curious... Pinmemberjeron126-Sep-12 11:02 
GeneralRe: OT Just curious... PinmvpCPallini26-Sep-12 11:14 
GeneralRe: OT Just curious... Pinmemberjeron126-Sep-12 12:15 
Questionproblem deploying application Pinmembersujandasmahapatra25-Sep-12 8:40 
AnswerRe: problem deploying application PinmemberChris Meech25-Sep-12 9:00 
GeneralRe: problem deploying application Pinmembersujandasmahapatra25-Sep-12 21:28 
GeneralRe: problem deploying application PinmvpRichard MacCutchan25-Sep-12 22:00 
GeneralRe: problem deploying application Pinmembersujandasmahapatra26-Sep-12 21:02 
GeneralRe: problem deploying application PinmvpRichard MacCutchan26-Sep-12 21:29 
Questionexceptions always SIGABRT in linux shared object PinmemberMichaelRoop25-Sep-12 1:28 
AnswerRe: exceptions always SIGABRT in linux shared object PinmvpRichard MacCutchan25-Sep-12 6:04 
GeneralRe: exceptions always SIGABRT in linux shared object PinmemberMichaelRoop25-Sep-12 11:02 
GeneralRe: exceptions always SIGABRT in linux shared object PinmemberMichaelRoop25-Sep-12 13:45 
QuestionCppunit in Visual studio 2010 PinmemberRahul from Poona24-Sep-12 4:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 23 Jul 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid