Random function does not work random

Hi guys

For an implementation of the travelling tournament problem I'm in bad need for a random function.

Now I'm testing with the standard randomizer in cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
        srand((unsigned) time(0));

	move = rand() % 5;
	firstTeam = 1 + int(((this->numbOfTeams) * rand()) / (RAND_MAX + 1.0));
        secTeam = firstTeam;

	firstRound = int(((this->numbOfRounds) * rand()) / (RAND_MAX + 1.0));     
        secRound = firstRound;

	while(firstTeam == secTeam)
		secTeam = 1 + int(((this->numbOfTeams) * rand()) / (RAND_MAX + 1.0));

	while(firstRound == secRound)
		secRound = int(((this->numbOfRounds) * rand()) / (RAND_MAX + 1.0));


Little explanation: I want 5 random numbers. firstTeam and secTeam may not have the same value. Also for firstRound and secRound.

This works in my debugger. But when I actually run the code and output my fresh generated numbers it does not randomize.

anybody knows how come?

greetz

Lyven
Ok, found the solution, because I use the function alot with large frequency, i should put the srand((unsigned) time(0)); at the start of my program. Seeds etc...
Topic archived. No new replies allowed.