I guess creating an iterator that saves each randomized numbers in an integer array of that size(i.e. 1000) would do it and on each iteration, a variable of type integer would increase by 1 if the number generated is less than 5.
1 2 3 4 5 6 7 8 9
constint size=1000;
int counter=0;array[size];
for(int x=0;x<size;x++)
{
//y=your random number should be generated here.
// if y<5, increase the counter by 1, that is, counter+=1;
// array[x]=y;
}
//print out your counter