Whats the best way to take readings from a sensor over time?

So I have this code

float Sensors::getLightAveraged(int ms, int numberOfReadings){
    float intervalBetweenReadings = (float)ms/(float)numberOfReadings;
    float allReadings[numberOfReadings];
    int numberOfReadingsTaken = 0;

    while (numberOfReadings >= numberOfReadingsTaken){
        allReadings[numberOfReadingsTaken] = getLightInstantanious();
        numberOfReadingsTaken++;
    }

    return averageOfArray(allReadings);
}

What I want it to do is return the average reading from my light sensor, over a set time and number of readings.

What is the best way to call my getLightInstantanious() function in the while loop every intervalBetweenReadings milliseconds (this won’t be a necessarily be a whole number of ms either)