Thread: how to program zipfian distribution

  1. #1
    Registered User
    Join Date
    May 2008

    how to program zipfian distribution

    The thing is this: A line range is between a and b, in x axis. I have to generate random numbers according to the zipfian distribution(skewed towards a) in that range, but I have not found the way to manipulate a function to do that.

    Some idea?

    Thanks a lot!"!

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    May 2008

    Wink some code

    now i find some code about zipfian, which gives the range between x1 and x2

    double HsubV=0;
    void InitZipfHsubV(double p,int V=100) {
    	// calculate the V-th harmonic number HsubV. WARNING: V>1
    	HsubV = 0.0;
    	for (int i=1; i<=V; i++)
    		HsubV += 1.0/pow( (double)i, p); //Hsub=zipfian 1/c
    //int ino[105]={0};
    float drd;
    float zipf(float x1, float x2, double p,int V=100) {
       float x,i;
       double r, sum;
       do {
    	   // assume InitZipfHsubV called, HsubV known
    	   // faster, no need to compute HsubV every time !
    	   drd = drand48();
    	   drd = drand48();i=drd;
    	   while (sum<r){
    	      //i++;  //commented by Yufei Tao
    		  drd = drand48(); i+=drd+1.0;
    	      sum += 1.0/pow( (double)i, p);
    	   /* i follows Zipf distribution and lies between 1 and V */
    	   /* x lies between 0. and 1. and then between x1 and x2 */
    	   x = ( (float) i - 1. ) / ( (float) V - 1. );
    	   x = (x2 - x1) * x + x1;
    	   //if( x > x1 && x < x2 ) ino[int(ceil(i))]++ ;//printf( "i:%f r:%f x:%f\n",i,r,x );
       } while (x < x1 || x > x2);

  4. #4
    Registered User
    Join Date
    May 2008

    Question i don't know what u mean?

    can u tell me in detail?please

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  2. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  3. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM