Hi, I want to write a function that takes the array size as parameter, and genereates random number as elems b/t 0 and twice the array size, but it's not working as the random values for each compiling is ALWAYS the same.
Call srand(time(0)) between lines 38 and 29. This seeds the random generator to the system time. Otherwise you'll see you get the results you describe, where it always starts of at the same point in the pseudo random sequence.
Thanks that worked by putting into main, but it also works if I remove from the for loop in function createArray but still place it ( srand(time(0)) ) within createArray.
You should only call srand once at the start of your program and never again to prevent fast code execution from giving you the same random numbers over and over. You must realize most simple programs like this take far less than a second to execute and time(0) only changes every second ;)