0

i can't for the life of me figure out how to write

int num;

num = rand() %. ...

i need a range of 0 to 1
I want to store either zero or one to num. That is my goal. plz help
(i'm a noob obviously)

2
Contributors
2
Replies
3
Views
12 Years
Discussion Span
Last Post by steosaur(oWn)
0

i can't for the life of me figure out how to write

int num;

num = rand() %. ...

i need a range of 0 to 1
I want to store either zero or one to num. That is my goal. plz help
(i'm a noob obviously)

#include <iostream>
#include <ctime> 
#include <cstdlib> 

using namespace std;

int main()

{

int hello = 0;

srand(time(0));

hello = 1 + rand() % 2;

cout << hello;

return 0;

}

Perhaps that may help. srand is similar to rand apart from it seeds it. The time in brackets tells the proram to take the current time of the system clock and produce a randomn event based on it. This program will print a 1 or a 2 depending.

I hope this helps you in the right direction

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.