1 2 3
|
insert = 1 + rand() % 69;
v.erase(v.begin() + i);
v.push_back(insert);
|
This is wasteful and inefficient. You generate a random number, and add it to the end, without checking if it's a duplicate? Why not check when you generate it, instead of going through that extra work?
Also, it doesn't work. It generates duplicates.
What happens if you're doing 4 such values, and your array looks like this because you've already done 3:
1 2 3
and then you generate another number, and it's 2 again. i never goes back, so you wouldn't know it was a repeat? So you can have duplicates.
Here's your code generating duplicates:
http://cpp.sh/8bwzd
Hit run a few times to see it generate duplicates.
Even if it didn't generate duplicates, it doesn't scale well. If I wanted 999999999 different numbers from a choice of 1000000000, I could be waiting quite a while; I would randomly generate so many duplicates before I got a new number.
You've used rand, which is a bad choice in and of itself, for many reasons.
https://channel9.msdn.com/Events/GoingNative/2013/rand-Considered-Harmful
I think you'd be better off with a vector of all the numbers, shuffling it (
http://www.cplusplus.com/reference/algorithm/shuffle/ ) , and then taking however many you want from the front. That solution would scale better.