I have a function that needs to generate, in a specific part, a random number to do a certain task. But whenever the program enters this function, the number generated does not change, always being zero. Here is the code:
do{ // Garante que seja escolhido um item que ainda nao esteja na mochila
srand( (unsigned) time (NULL) ); // Gera um numero aleatorio, usado para selecionar um item qualquer na lista de itens disponiveis
item_position = rand() % num_items;
printf("item_position: %d", item_position);
j = 0;
while(j < index_items->size())
{
printf("Item escolhido: %d \n\n\n", item_position);
if(item_position == index_items->at(j)) // Verifica se o item escolhido aleatoriamente ja nao esta na mochila
itens_repetidos += 1; //Dessa forma, evita repeticoes dentro da mochila
j++;
}
}while(itens_repetidos != 0);
As seen in the code, I use the srand and rand functions to generate the number. What could be wrong?