Generating a time series by using Uniform Distributed Random Number Generator quickly please!!!!

My assignment is as so: "Visual C provides a function RAND() to generate a uniformly distributed random value
between [0, 1]. (You must include “stdlib.h” in the header.) Another function SRAND(#)
inputs the seed (#) to RAND(). For identical seed (#), RAND() will generate the same
sequence of random numbers. Use a constant value for seed (do NOT use # = time) in order
to simplify the debugging process.
In the first exercise with initial value of t0 = 0, write a C program to generate one random
value (r1) between [0, 1] with a chosen seed (s1). Add this random value to t0 and calculate
t1 = t0 + r1. AFTER calculate t1, generate r2 and calculate t2 = t1 + r2. Repeat the process
for ten random values r1 to r10 and t1 to t10. List r1 to r10 and t1 to t10 in a table.
Repeat the same exercise with a different seed (s2). A different seed will generate a different
sequence of random numbers. Different random number sequences are needed in order to run
the simulation several times for different results.
Deliverable 1:
List the two sets (seed1 and seed 2) of time series (i; ri; ti) in tables.
"



The code I have been able to come up with till now was as so:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
#include <string>
#include <random>
#include <ctime>
#include <cstdlib>
#include <cmath>

using namespace std;

int main(){
	int s1, s2;
	float i, r;
	float t0 = 0;
	float i = 0;
	double t(i) = r + t(i-1);

	  
for(s1 = 1;;s1++);
{
srand(s1);
s1 = rand();
printf("%d\n",s1);
}


for(i = 0; r <= 1 && r > 0; i++){ 
r = rand();

while (i<11){

	cout << r << i <<endl;


}




	system("PAUSE");
	return 0;
}}


But it doesn't work properly, I also mainly don't know how to properly implement the t1=t0+r1, t2=t1+r2,...so on till t10=t9+r10
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
#include <random>
#include <iomanip>
#include <cstdlib>
using namespace std;

void main(){
	int s1 ;
	double r;
	int i=0;
	double t;
		t= t + r;

for(s1 = 1;;s1++);
{
srand(s1);
r = rand()/((double)RAND_MAX);
printf("%d\n",s1);
}


for(i = 0; r <= 1 && r > 0; i++){ 
r = rand();

while (i<11){

	cout << setw(15) << t << setw(15) << r <<endl;

}
	system("PAUSE");
	return 0;
}}
Topic archived. No new replies allowed.