Hmm... The write to file and read it back is using too many resources and is not optimal.
I am not clear about your question. Do you mean you want to...
1) create a random generated number between a and b (inclusive) for an array size of 50
2) count frequency of each number between a and b in the array
2.1) AFTER the array is generated, OR
2.2) DURING the array is generated
3) when counting, you CAN or CANNOT use other built-in function
By the way, from PHP documentation stated, mt_rand($min, $max) gives a better result than rand($min, $max). Just for your information.