clock() is a good idea.
trying to seed srand() with the result of clock().
seem right?
not exactly getting the desired result. all random numbers are the same. but I think i'm closer.
Code:
#include<stdio.h>
#include<omp.h>
#include<windows.h>
#include<stdlib.h>
#include<time.h>
main()
{
int th_id,x0,x1,x2,x3,x4,x5,x6,x7;
clock_t start_0,start_1,start_2,start_3,start_4,start_5,start_6,start_7,stop_0,stop_1,stop_2,stop_3,stop_4,stop_5,stop_6,stop_7;
double duration_0,duration_1,duration_2,duration_3,duration_4,duration_5,duration_6,duration_7;
#pragma omp parallel private(th_id)
{
srand(time(NULL)); /*x = (rand() % (max - min + 1) + min);*/
while(1)
{
//---------------INDIVIDUAL THREAD TASKS RUNNING IN PARALLEL-----------------
th_id = omp_get_thread_num();
if(th_id==0)
{
start_0 = clock();
}
if(th_id==1)
{
start_1 = clock();
}
if(th_id==2)
{
start_2 = clock();
}
if(th_id==3)
{
start_3 = clock();
}
if(th_id==4)
{
start_4 = clock();
}
if(th_id==5)
{
start_5 = clock();
}
if(th_id==6)
{
start_6 = clock();
}
if(th_id==7)
{
start_7 = clock();
}
if(th_id==0)
{
stop_0 = clock(); // get number of ticks after loop
duration_0 = ( double ) ( stop_0 - start_0 ) / CLOCKS_PER_SEC;
srand(duration_0);
x0 = (rand() % (7 - 1 + 1) + 1);
}
if(th_id==1)
{
stop_1 = clock(); // get number of ticks after loop
duration_1 = ( double ) ( stop_1 - start_1 ) / CLOCKS_PER_SEC;
srand(duration_1);
x1 = (rand() % (7 - 1 + 1) + 1);
}
if(th_id==2)
{
stop_2 = clock(); // get number of ticks after loop
duration_2 = ( double ) ( stop_2 - start_2 ) / CLOCKS_PER_SEC;
srand(duration_2);
x2 = (rand() % (7 - 1 + 1) + 1);
}
if(th_id==3)
{
stop_3 = clock(); // get number of ticks after loop
duration_3 = ( double ) ( stop_3 - start_3 ) / CLOCKS_PER_SEC;
srand(duration_3);
x3 = (rand() % (7 - 1 + 1) + 1);
}
if(th_id==4)
{
stop_4 = clock(); // get number of ticks after loop
duration_4 = ( double ) ( stop_4 - start_4 ) / CLOCKS_PER_SEC;
srand(duration_4);
x4 = (rand() % (7 - 1 + 1) + 1);
}
if(th_id==5)
{
stop_5 = clock(); // get number of ticks after loop
duration_5 = ( double ) ( stop_5 - start_5 ) / CLOCKS_PER_SEC;
srand(duration_5);
x5 = (rand() % (7 - 1 + 1) + 1);
}
if(th_id==6)
{
stop_6 = clock(); // get number of ticks after loop
duration_6 = ( double ) ( stop_6 - start_6 ) / CLOCKS_PER_SEC;
srand(duration_6);
x6 = (rand() % (7 - 1 + 1) + 1);
}
if(th_id==7)
{
stop_7 = clock(); // get number of ticks after loop
duration_7 = ( double ) ( stop_7 - start_7 ) / CLOCKS_PER_SEC;
srand(duration_7);
x7 = (rand() % (7 - 1 + 1) + 1);
}
//----------------------------------------------------------------------------
printf("%d%d%d%d%d%d%d%d\n",x0,x1,x2,x3,x4,x5,x6,x7);
}
} //end of parallel section
}