Possible Duplicate:
Repeated random number in a loop
thanks for the comments before, i updated the code.
First in the main function i call the srand
int main ()
{
//DefineRelationstozero (); //All predecessors are set to -1
srand((unsigned)time(0));
.......
......
......
for (int k=0;k<iterationnumber;k++)
{
.....
RandomKey ();//i call randomkey for every iteration
}...
void RandomKey ()
{
for (int k=0;k<ActivityNumber;k++)
{
Act_num[k].Priority=(rand()%10000)*0.0001;//random number
}
for (int i=0;i<ActivityNumber;i++)
arr[i]=Act_num[i].Priority;
....
开发者_运维知识库
RESULT: for every iteration i got exactly same numbers in arr[]
maybe Act_num[k].Priority is int. When you call:
(rand()%10000)*0.0001
it gives you number from <0, 0.999>. So, if Act_num[k].Priority is integer then you get floor from this random number. So it's 0 for all time
精彩评论