+ 2
How to make the program generate some numbers without repeating the same number?
I want to make a program that can generate the number of questions that students answer in class. But when I use “srand”, I find that many numbers are repeated many times. It even generated 9 numbers with five 2’s and four 1’s. As I know, questions can’t be answered more than twice. So what is the solution to the problem using C++? Just like: 1 3 2 4 or 2 3 4 1. Each number is allowed to appear only once.
3 Antworten
+ 2
How to make it? hinanawi
+ 1
store the numbers in a list/vector and then check if the generated number is already in there, if so, generate another one
+ 1
Alice here, this returns a TLE on SL (sometimes) but on regular compilers it should work fine
(i hate the random function in c++)
https://code.sololearn.com/cbFvTe5wSITG/?ref=app