list of 10 random numbers

I'm working on a bunch of sorting algorithems. I need to sort an array of x numbers.
Unfortunately I stumbled acros a problem.

If I make an random array of numbers below 10. There are some large numbers passed in that i didn't declare.

This is my code:

int quantity = 10;
list[]={};

void randomarray(quantity)
{

for (int i=0; i< quantity; i++)
{
int randint = random(0,quantity);
list = randint;

  • }*
    }
    If I print the array i get something like this:
    3
    1
    261
    2
    514
    8
    777
    5
    0
    8
    Where in earths name do these large numbers come from?
    I can't figure it out! :fearful:

Welcome!
Try to use

 list[i] = randint;

instead of

 list = randint;

and also use code button for source code to be better readable.
EDIT: You've printed a random memory regions since list = randint; command changed a pointer to array not a value inside of array.

Thank you very much!
What a great site is this.

That's what I have, I accidently forgot that part when I was translating it from dutch.
I'm sorry!

Do you have any idea how the large numbers are passed in with this code?

and

Can I give you credit for your help? :stuck_out_tongue:

Budvar10:
Welcome!
Try to use

 list[i] = randint;

instead of

 list = randint;

and also use code button for source code to be better readable.
EDIT: You've printed a random memory regions since list = randint; command changed a pointer to array not a value inside of array.

In fact it's the lack of code tags that took out the i index in square brackets and turned on italics instead.

Wow! You guys helped me out too! I am working on a similar project where I am printing random numbers on 16X2 LCD using this tutorial. Thanks! :slight_smile: :smiley:

This will not give you random numbers. Only Psuedo-Random numbers.

UnderGround_Hacker:
This will not give you random numbers. Only Psuedo-Random numbers.

You need truly random numbers to test your sorting algorithms? The question was not about random numbers; it was about sorting algorithms.

I prefer pseudo-random as then the sort has exactly the same work to do each time I test.

@JimboZA

In fact it's the lack of code tags that took out the i index in square brackets and turned on italics instead.

Thank you sir. :-[

@Guido83

Can I give you credit for your help?

I do not deserve. Give it to Delta_G for the post above.

@ Delta_G

Thank You,
This is what i needed to know!

It works perfectly now! :smiley: