samedi 12 novembre 2016

Some Explanation To My Random Number Generator Issue -- Repeating value [duplicate]

This question already has an answer here:

I'm having issue with my random number generator. My goal is to have a random double from 0 to 1.

  double randNum() {
  double R = 0;
  srand(unsigned(time(NULL)));
  R = rand()/(double)RAND_MAX;
  return R;
  }

This double function is being called inside of a recursive function which would give an arbitrary ID to an employee, with each employee actually being part of a binary tree. However, my output comes out with each employee having the same arbitrary ID:

Rich            0.12994                                                                                                                                    
Mauve           0.12994                                                                                                                                    
Joe             0.12994                                                                                                                                    
Benny           0.12994

Any ideas to fix this issue? Or at least, whats the reasoning behind the issue?




Aucun commentaire:

Enregistrer un commentaire