Mail Archives: djgpp/1997/04/08/05:01:52
I am having a major problem with my program. The random fuction does not
seem to be working right.
random() & 9 only returns 0, 1, 8, and 9. I put the funcition in a loop
and that is the only numbers it ever returns. I then changed the 9 to a
5 and then I got 0,1,4, and 5. I need to get all the intergers within
that range not just the four extremes. Can anybody explain why this is
happening. I am using c++ and here is a sample code statement that
illustrates my point.
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <iostream.h>
int n;
for(n=0; n < 10; n++)
cout << (random() & 9);
Thank you for your time.
- Raw text -