For Loops(Random variables)

I made a for loop and I was hoping that it'd make the D variable I put in the paranthesis for ( ) a random number each time
How do I make it so I can get a random variable for the D value

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void read_and_total(int acctNum, int dataUsed, int time Used)

{

int D,
P;

for (D =0; D <= 1000; D++)
{
dataUsed = dataUsed + D;
}
{
for (P = 0; P <= 1000; P++)

timeUsed = timeUsed +P;
}

Last edited on
- If you're ok with a pseudo-random number there're rand, srand and random functions in <stdlib.h>

- There are websites that generate genuine random numbers, unfortunately your application needs to access the generator on the website which obviously requires you to be online. Another option is use of a real HW random number generator.
Do you know which number, my program is spitting then?

and also I keep getting a 6 digit number
when I'm supposed to get a # thats a lot lower
That's because your loop adds all numbers from 1- 1000 to dataused. I guess that'd not what you want?

Topic archived. No new replies allowed.