0

I have to generate v shaped, ascending and descending random int array for sorting tests. I have no idea how to achive that. Here is my implementation for 100k array of random ints.

        Random rnd = new Random(Guid.NewGuid().GetHashCode());            
        int[] array = new int[100000];

        for (int i = 0; i < 100000; i++)
        {
            array[i] = rnd.Next(100000);
        }

Can somebody help me?

  • 3
    "*generate v shaped, ascending and descending random int array"* - can you describe what is it? Perhaps with an example of data set. – Sinatr Jun 07 '16 at 11:25

2 Answers2

3

Generate two lists of 50k - sort the first ascending, sort the second descending (Better way to sort array in descending order) & join the two arrays (How do I concatenate two arrays in C#?)

Community
  • 1
  • 1
PaulF
  • 6,673
  • 2
  • 18
  • 29
1

I have to generate v shaped, ascending and descending random int array for sorting tests

I would reconsider the scenario. This kind of test should not be based on random values. From a similiar question:

Randomly live-generated data in tests is not a good idea. there's no way you can guarantee the test conditions will be the same every time, and no guarantee that you cover every possible scenario.

Instead you can simply make sure that a specific scenario is covered.

        int numberOfItems = 100000;
        int[] array = new int[numberOfItems];
        int count = 0;

        for (int i = numberOfItems / 2; i > 0; i--)
        {
            array[count++] = i;
        }

        for (int i = 0; i < numberOfItems / 2; i++)
        {
            array[count++] = i;
        }
Community
  • 1
  • 1
smoksnes
  • 10,509
  • 4
  • 49
  • 74