Error when trying to sort an array

Hi everyone,

I have a small issue when trying to sort an array of random values between firstTime and lastTime. Basically, I generate an array (double scrambledDataTime) of size numOfEvents with random values with the mentionned limits and then use the TMath::Sort function to sort in increasing order and store the sorted values in double sortedScrambledDataTime array that I have correctly define previously (same size as scrambledDataTime).

for (int l = 0 ; l < numOfEvents ; l++) { scrambledDataTime[l] = firstTime + static_cast <float> (rand()) /( static_cast <float> (RAND_MAX/(lastTime-firstTime))); } TMath::Sort(numOfEvents,scrambledDataTime,sortedScrambledDataTime,false);

When doing this, I get an error telling me that the function Sort is not defined in the current scope. Any idea why I get this error? When I do “TMath::S” + tabulation in ROOT, it does find the function.

Thank you in advance :slight_smile:

My bad! I just realized that the Sort function sort the index of the array, not the values assigned to each index. After changing the double type of sortedScrambledDataTime to an int, it worked :slight_smile: