Hey everyone! I'm working on a project where I need to sort arrays consisting of sizes ranging from 32 up to about 1,048,576 (which is 2^20). I want to sort them in three different orders: already sorted, reverse sorted, and completely random. What's the best method to generate arrays of that size? Any suggestions or tips would be super helpful. Thanks!
3 Answers
What programming language are you using? A simple way is to start with a list of numbers from 1 to N, and then keep removing one at random to form your new list. Repeat until you have N numbers in random order.
You might want to search for "how to create a random integer array of size N in [your programming language]". There's usually a lot of resources out there for that!
Thanks for the tip! I’ll check that out!
You don't really need to complicate things. Just create a big array and use a loop to fill it with random numbers. Trust me, 2^20 isn't too overwhelming for modern systems!
But remember, OP just needs N random numbers, so you don’t have to stick to just 1 to N!