A test for the number theorists that may lurk here!
Given a positive integer may start with 1, 2, 3, ... or 9 you might think that there'd be a 1/9 or approximately 11% chance any random positive integer would start with a first digit of 1. Or that there would be just as many numbers starting with 9 as there are numbers starting with 1, but numbers starting with 9 as a first digit are the rarest occuring only 4.5% of the time.
PS
Something that Insurance acturaries and forensic auditors were slow to catch onto as they looked for evidence that folk were cooking the books. But eventually number theorists told them of this result and why it occurs and now they have a brand new series of tests for spotting cases of fraud.
PPS
Number frequencies of the first digit of all positive integers is to one decimal place:
1 as the starting digit occurs 30.1% of times in all positive integers
2 as the starting digit occurs 17.6%
3 as the starting digit occurs 12.5%
4 as the starting digit occurs 9.7%
5 as the starting digit occurs 7.9%
6 as the starting digit occurs 6.7%
7 as the starting digit occurs 5.8%
8 as the starting digit occurs 5.1%
9 as the starting digit occurs 4.6%
You'd see this trend if you (correctly wrote a C program like)
Code:
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <constants.h>
#include <signal.h>
#define Prime1 7234567897987978.....89091L
#define Prime2 63476324789324........87343L
#define Prime3 578457843879435.....909003L
#define Prime4 1382387248727498...348347L
#define Prime5 123427834832743....324224L
external unsigned long rand(), srand(); /* standarised random number generator and seed */
unsigned long i = 0L, counter[10] = {0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L};
unsigned long very_rand() /* even more random number generator */
{
return (rand() % Prime1 % Prime2 % Prime3 % Prime4 % Prime5);
}
VOID print_results()
{
int j;
signal(SIG_INT, SIG_IGN); /* ignore stacked interrupts */
printf("\nResults\n");
for (j = 0; j < 10; j++)
printf(" Digit %1d" occurs with frequency %2f \n", j, (float)(counter[j] * 100 / i) );
signal(SIG_INT,print_results); /* re-set interrupt handler to be this function */
}
main()
{
char buffer[64];
srand( (unsigned)time( NULL ) ); /* Seed random number generator */
signal(SIG_INT, print_results); /* if user presses interupt CTRL-C print interim results */
for (i = 0L; i < ULONG_MAX; i++, counter[(int)(buffer[0] - '0')]++ )
ssprinf(buffer, "%ld", very_rand() ); /* count the first digit of a random number*/
print_results(); /* print out your results */
}
Note very_rand() returns an unsigned long int that has been modded (%) with five big primes to make it extremely random! The modding (remainder from an integer division) makes teh random number act as if it was generated randomly form a pool of about 4 trillion raised to the fifth power!