M
Masud
hi,
for a test i want to generate different random numbers between
different ranges in a single loop. I tried to solve in the following
way but it always profile same value. I am looking for suggestion in
this regard.
#include <cstdlib>
#include <time.h>
#include<iostream.h>
int main()
{
int i,j;
for(i=0;i<n;i++) //N set of rendom numbers
{
j=randomize(1,5); // first number
cout<<j;
j=randomize(1,6); // second number and so on..
cout<<j;
}
}
int randomize(int LOW,int HIGH)
{
int value;
time_t seconds;// Declare variable to hold seconds on
//clock.
time(&seconds);//Get value from system clock and place in
//seconds variable.
srand((unsigned int) seconds);//Convert seconds to a
//unsigned integer.
value = rand() % (HIGH - LOW + 1) + LOW;//Get the random
//value between LOW and HIGH
return value;
}
for a test i want to generate different random numbers between
different ranges in a single loop. I tried to solve in the following
way but it always profile same value. I am looking for suggestion in
this regard.
#include <cstdlib>
#include <time.h>
#include<iostream.h>
int main()
{
int i,j;
for(i=0;i<n;i++) //N set of rendom numbers
{
j=randomize(1,5); // first number
cout<<j;
j=randomize(1,6); // second number and so on..
cout<<j;
}
}
int randomize(int LOW,int HIGH)
{
int value;
time_t seconds;// Declare variable to hold seconds on
//clock.
time(&seconds);//Get value from system clock and place in
//seconds variable.
srand((unsigned int) seconds);//Convert seconds to a
//unsigned integer.
value = rand() % (HIGH - LOW + 1) + LOW;//Get the random
//value between LOW and HIGH
return value;
}