この種のことに対する答えがあることはすでに知っていますが、コードにそれらを実装する方法が本当にわかりません。また、必要以外の機能の使用は控えたいと思います。これが私のコードです:
int main()
{
unsigned seed;
seed = 1;
srand(seed);
std::string starFox[8];
int x[8];
starFox[0] = "Do a barrel roll!";
starFox[1] = "Try a somersault!";
starFox[2] = "Use bombs wisely!";
starFox[3] = "Something is wrong with the G-diffuser";
starFox[4] = "Can't let you do that, Star Fox";
starFox[5] = "Hey Einstein, I'm on your side";
starFox[6] = "Whoa! help me!";
starFox[7] = "Daddy screamed REAL good before he died!";
for(int i=0; i<8; i++)
{
int y = 0 + rand() % 8;
x[i] = y;
if (x[i-1]!=y || x[i-2]!=y || x[i-3]!=y || x[i-4]!=y || x[i-5]!=y || x[i-6]!=y || x[i-7]!=y)
{//now I need to make a statement that makes sure each number appears once.
std::cout << starFox[y] << "\n";}
}
std::cout << '\n';
return 0;
}
では、プログラムが実行されるたびに乱数を生成するには、このコードに何を変更すればよいでしょうか?