Skip to content

Instantly share code, notes, and snippets.

@antirez
Created January 21, 2010 21:03
Show Gist options
  • Save antirez/283192 to your computer and use it in GitHub Desktop.
Save antirez/283192 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <math.h>
unsigned long longtailprng(unsigned long min, unsigned long max, int n) {
unsigned long pl;
double r = (double)(random()&(INT_MAX-1))/INT_MAX;
max += 1;
pl = pow((pow(max,n+1) - pow(min,n+1))*r + pow(min,n+1),1.0/(n+1));
return (max-1-pl)+min;
}
int main(void) {
int i;
for (i=0; i<10; i++)
printf("%lu\n",longtailprng(0,10,2));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment