0
There is difference in the generation of these random numbers?
I made 2 codes for show 6 random numbers, both work, but I don't know if randint is better for my intention or it is range. https://code.sololearn.com/cMmBU6RRDU8n/?ref=app https://code.sololearn.com/c8CLSs7OKs0H/?ref=app
1 Réponse
+ 4
What do you think which one is better? Which one was easier/more pleasant to write? The one with a predefined method that does exactly what you want (pick x numbers from a range of y numbers without repetitions) or the one where you had to write everything by hand, making sure that you don't forget to check any case (is the fourth number equal to the sixth or the second to the third etc.)?
Imagine you had to pick 20 random numbers instead of 6, and you had to make sure that there are no repetitions, what would the statement "if a != b and a != c and a != d and a != e and a != f and b != c and b != d and b != e and b != f and c != d and c != e and c != f and d != e and d != f and e != f:" look like?
/Edit: By the way, your second code isn't guaranteed to find six unique numbers. It just checks if the numbers are all different and if they aren't, it asks the user to try again (I guess?)... Hm.