How can I generate large random arrays for sorting tests?

0
0
Asked By TechieBunny42 On

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

Answered By RandomNumberNinja On

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.

CodeCrafter88 -

But remember, OP just needs N random numbers, so you don’t have to stick to just 1 to N!

Answered By DevGuru2023 On

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!

TechieBunny42 -

Thanks for the tip! I’ll check that out!

Answered By CodeCrafter88 On

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!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.