C++ rand()每个数字只有一次

use*_*608 1 c++ random numbers srand

我需要像rand()这样的东西,但我只希望每个数字一次.

在示例中,我有10个".txt"文件,这些文件被命名为数字(1-10).我想读一下里面的东西,然后cout它,但随机.

我不想1.txt - > 2.txt - > 3.txt - > ...但是随机的东西就像

5.txt - > 4.txt - > 1.txt - > ...

每个号码只应出现一次

是否有捷径可寻?

string Path = "./Questions_Niko/" + random + ".txt"; 
Run Code Online (Sandbox Code Playgroud)

mer*_*011 6

创建所需数字的向量并使用std :: shuffle.

然后按顺序迭代向量.