Returning a pointer

I am trying to return a array of random numbers and it does not work

receiving: int *random = new int [4];


creating random:
1
2
3
4
5
6
7
int * createrandomcolors()
{
    int *random = new int [4];
    for (short int m =0 ; m < 4; m++){
    random[m] = rand() % 6 + 1;  }
    return random;
}

when I cout it gives a very long number
help please
closed account (zb0S216C)
When you return a pointer to memory allocated within a function, you're passing ownership of the memory to the pointer that accepts the pointer returned by your function.

The long number can either be rubbish or a number generated by your function.

Wazzak
What are you passing to cout, exactly? Are you accidentally displaying the address instead of the contents of the address?
ok Now, i added a cout statement. but the random only gives me 6 6 5 5 all the time. I solved the pointer problem
help please
You need to seed the random generator by using srand.
alright thanks!
Topic archived. No new replies allowed.