我正在尝试生成两个随机数数组。一个数组用于高度,另一个用于文本艺术鱼缸的宽度。但是数组总是有相同的重复数字。
例如:[ 2, 2, 2, 2 ] 或 [ 9, 9, 9]
我一定是错误地设置了循环,但我需要帮助看看出了什么问题。
//Generate random numbers for fish positions in vector
if ( fish_collection.size() != 0 )
{
int randHeight[fish_collection.size()];
int randWidth[fish_collection.size()];
for ( int i = 0; i < fish_collection.size(); i++ )
{
srand (time(NULL));
randHeight[i] = rand() % 10 + 1;
randWidth[i] = rand() % (tank_size - 5) + 1;
}
//random number printed test
for ( int i = 0; i < fish_collection.size(); i++ )
{
cout << randWidth[i] << ',';
}
cout << endl;
//Enter the fish in random position
for ( int j = 0; j < fish_collection.size(); j++ )
{
tank_frame[randHeight[j]].replace ( randWidth[j], fish_collection[j].size(), fish_collection[j] );
}
}