How to Fill an Array with Random Unique Numbers in Python

preview_player
Показать описание
In this Python tutorial I will be teaching you guys how to fill an array with random unique numbers. Meaning that there are no duplicates in the array! It's a quite simple algorithm and I hope you guys enjoy!

A couple things I didn’t mention in the video:

If you make your rangeOfNumbers equal to or less than totalUniqueNumbers then the algorithm will loop forever. You really DON’T want that. So the best way to prevent such a thing from happening is to put in a catch.

If rangeOfNumbers equal to or less than totalUniqueNumbers:

Tell the user that the program will never stop.

And then stop the program lol
However, if there is no user input, then this really shouldn't be an issue. But if your code is seemingly running forever, this could be your issue.

Feel free to use this for your next data structure's test, just make sure to tell your teacher to subscribe to me!

Source code from the video can be found here:

--Ruby Programs or you can just call me Ruby Penguin. It's whatever idc
Рекомендации по теме
Комментарии
Автор

It was great! I am stuck in problem like an array should have five elements and inside each element use random function to create a single random number 0-9 and place that number inside the element without adding the numbers, whenever 7 digit is complete, fill the next element with the random numbers one by one.

relax_habibi
Автор

Guys, this is a horrible solution! I hope you know this, now that you're way more familiar with Python I hope we get a follow up :)

filthypenguintv
welcome to shbcf.ru