test_skim_sketch.cpp
int zipf(double alpha, int n)
{
  static int first = 1;      // Static first time flag
  static double c = 0;          // Normalization constant
  double z;                     // Uniform random number (0 < z < 1)
  double sum_prob;              // Sum of probabilities
  double zipf_value = 1;            // Computed exponential value to be returned
  int    i;                     // Loop counter

  // Compute normalization constant on first call only
  if (first == 1)
  {
    for (i=1; i<=n; i++)
      c = c + (1.0 / pow((double) i, alpha));
    c = 1.0 / c;
    first = 0;
  }

  // Pull a uniform random number (0 < z < 1)
  do
  {
    z = rand_val(0);
  }
  while ((z == 0.0) || (z == 1.0));

  // Map z to the value
  sum_prob = 0;
  for (i=1; i<=n; i++)
  {
    sum_prob = sum_prob + c / pow((double) i, alpha);
    if (sum_prob >= z)
    {
      zipf_value = i;
      break;
    }
  }

  // Assert that zipf_value is between 1 and N
  assert((zipf_value >=1) && (zipf_value <= n));

  return(zipf_value);
}
//===========================================================================
//=  Function to generate Zipf (power law) distributed random variables     =
//=    - Input: alpha and N                                                 =
//=    - Output: Returns with Zipf distributed random variable              =
//===========================================================================
Function to generate Zipf (power law) distributed random variables
Input: alpha and N
Output: Returns with Zipf distributed random variable
Function to generate Zipf ( power law ) distributed random variables Input : alpha and N Output : Returns with Zipf distributed random variable
int zipf(double alpha, int n)
{
  static int first = 1;      
  static double c = 0;          
  double z;                     
  double sum_prob;              
  double zipf_value = 1;            
  int    i;                     
  if (first == 1)
  {
    for (i=1; i<=n; i++)
      c = c + (1.0 / pow((double) i, alpha));
    c = 1.0 / c;
    first = 0;
  }
  do
  {
    z = rand_val(0);
  }
  while ((z == 0.0) || (z == 1.0));
  sum_prob = 0;
  for (i=1; i<=n; i++)
  {
    sum_prob = sum_prob + c / pow((double) i, alpha);
    if (sum_prob >= z)
    {
      zipf_value = i;
      break;
    }
  }
  assert((zipf_value >=1) && (zipf_value <= n));
  return(zipf_value);
}
int zipf ( double alpha , int n ) { static int first = 1 ; static double c = 0 ; double z ; double sum_prob ; double zipf_value = 1 ; int i ; if ( first == 1 ) { for ( i = 1 ; i <= n ; i ++ ) c = c + ( 1.0 / pow ( ( double ) i , alpha ) ) ; c = 1.0 / c ; first = 0 ; } do { z = rand_val ( 0 ) ; } while ( ( z == 0.0 ) || ( z == 1.0 ) ) ; sum_prob = 0 ; for ( i = 1 ; i <= n ; i ++ ) { sum_prob = sum_prob + c / pow ( ( double ) i , alpha ) ; if ( sum_prob >= z ) { zipf_value = i ; break ; } } assert ( ( zipf_value >= 1 ) && ( zipf_value <= n ) ) ; return ( zipf_value ) ; }
Function to generate Zipf (power law) distributed random variables
 Input: alpha and N
 Output: Returns with Zipf distributed random variable
Function to generate Zipf ( power law ) distributed random variables Input : alpha and N Output : Returns with Zipf distributed random variable
// Static first time flag // Normalization constant // Uniform random number (0 < z < 1) // Sum of probabilities // Computed exponential value to be returned // Loop counter // Compute normalization constant on first call only // Pull a uniform random number (0 < z < 1) // Map z to the value // Assert that zipf_value is between 1 and N