我有一个整数列表intList = {1, 3. 5. 2}
(它只是一个示例整数和大小都未知)。我必须从该列表中选择一个随机数。从整数列表中选择一个随机数
RandomInt = rand() % intList.size()
将以类似的方式工作为RandomInt = rand() % 4
和产生到4到1之间的数randon而intList中是不同的。
如果我使用RandomInt = std::random_shuffle = (intList, intList.size())
仍然出错。我不知道如何从列表中选择一个随机数。
RandomInt =的std :: random_shuffle(intList中,intList.size()); –
'std :: random_shuffle'的范围从[first,last)到functor的可选附加参数。它也返回'void'。一个正确的调用看起来像'std :: random_shuffle(intList.begin(),intList.end())' –