Example #1
0
int main(){



    int i, j;
    uint32_t *array32 = (uint32_t *)array1;
    sfmt_t sfmt;

    if (sfmt_get_min_array_size32(&sfmt) > BLOCK_SIZE) {
	printf("array size too small!\n");
        return 0;
    }
    /* 32 bit generation */
    sfmt_init_gen_rand(&sfmt, 1234);
    for (i = 0; i < 10; i++) {
	for (j = 0; j < COUNT; j++) {
	    //sfmt_fill_array32(&sfmt, array32, BLOCK_SIZE);
	}
    }
    for(int k=0; k<2100000000; k++)
        sfmt_genrand_uint32(&sfmt);

}
Example #2
0
void InfGraph::BuildHypergraphR(int64 R){
    hyperId=R;
    //for(int i=0; i<n; i++)
        //hyperG[i].clear();
    hyperG.clear();
    for(int i=0; i<n; i++)
        hyperG.push_back(vector<int>());
    hyperGT.clear();
    while((int)hyperGT.size() <= R)
        hyperGT.push_back( vector<int>() );

    for(int i=0; i<R; i++){
        BuildHypergraphNode(sfmt_genrand_uint32(&sfmtSeed)%n, i, true);
    }
    int totAddedElement=0;
    for(int i=0; i<R; i++){
        for(int t:hyperGT[i])
        {
            hyperG[t].push_back(i);
            //hyperG.addElement(t, i);
            totAddedElement++;
        }
    }
}
Example #3
0
/** Initialize the SSL context.
 * \return pointer to SSL context object.
 */
SSL_CTX *
ssl_init(char *private_key_file, char *ca_file, int req_client_cert)
{
  const SSL_METHOD *meth;       /* If this const gives you a warning, you're
                                   using an old version of OpenSSL. Walker, this means you! */
  /* uint8_t context[128]; */
  DH *dh;
  unsigned int reps = 1;

  if (!bio_err) {
    if (!SSL_library_init())
      return NULL;
    SSL_load_error_strings();
    /* Error write context */
    bio_err = BIO_new_fp(stderr, BIO_NOCLOSE);
  }

  lock_file(stderr);
  fputs("Seeding OpenSSL random number pool.\n", stderr);
  unlock_file(stderr);
  while (!RAND_status()) {
    /* At this point, a system with /dev/urandom or a EGD file in the usual
       places will have enough entropy. Otherwise, be lazy and use random numbers
       until it's satisfied. */
    uint32_t gibberish[4];
    int n;

    /* sfmt_fill_array32 requires a much larger array. */
    for (n = 0; n < 4; n++)
      gibberish[n] = sfmt_genrand_uint32(&rand_state);

    RAND_seed(gibberish, sizeof gibberish);

    reps += 1;
  }

  lock_file(stderr);
  fprintf(stderr, "Seeded after %u %s.\n", reps, reps > 1 ? "cycles" : "cycle");
  unlock_file(stderr);

  /* Set up SIGPIPE handler here? */

  /* Create context */
  meth = SSLv23_server_method();
  ctx = SSL_CTX_new(meth);

  /* Load keys/certs */
  if (private_key_file && *private_key_file) {
    if (!SSL_CTX_use_certificate_chain_file(ctx, private_key_file)) {
      ssl_errordump
        ("Unable to load server certificate - only anonymous ciphers supported.");
    }
    if (!SSL_CTX_use_PrivateKey_file(ctx, private_key_file, SSL_FILETYPE_PEM)) {
      ssl_errordump
        ("Unable to load private key - only anonymous ciphers supported.");
    }
  }

  /* Load trusted CAs */
  if (ca_file && *ca_file) {
    if (!SSL_CTX_load_verify_locations(ctx, ca_file, NULL)) {
      ssl_errordump("Unable to load CA certificates");
    } else {
      if (req_client_cert)
        SSL_CTX_set_verify(ctx,
                           SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT,
                           client_verify_callback);
      else
        SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, client_verify_callback);
#if (OPENSSL_VERSION_NUMBER < 0x0090600fL)
      SSL_CTX_set_verify_depth(ctx, 1);
#endif
    }
  }

  SSL_CTX_set_options(ctx, SSL_OP_SINGLE_DH_USE | SSL_OP_ALL);
  SSL_CTX_set_mode(ctx,
                   SSL_MODE_ENABLE_PARTIAL_WRITE |
                   SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER);

  /* Set up DH callback */
  dh = get_dh1024();
  SSL_CTX_set_tmp_dh(ctx, dh);
  /* The above function makes a private copy of this */
  DH_free(dh);

  /* Set the cipher list to the usual default list, except that
   * we'll allow anonymous diffie-hellman, too.
   */
  SSL_CTX_set_cipher_list(ctx, "ALL:ADH:RC4+RSA:+SSLv2:@STRENGTH");

  /* Set up session cache if we can */
  /*
     strncpy((char *) context, MUDNAME, 128);
     SSL_CTX_set_session_id_context(ctx, context, strlen(context));
   */

  return ctx;
}
int main( int argc, char* argv[] )
{
  // Time coutning stuff
  timespec deb, fin, res;
  clock_t start;
  double exec;
  double elapsed;
  clock_getres(CLOCK_REALTIME, &res);
  
  // Create a reference generator
  sfmt_t an_sfmt;
  sfmt_t* ref = &an_sfmt;
  sfmt_init_gen_rand( ref, 25 );
  
  // Create a wrapped generator
  ae_jumping_mt* my_jumping_mt = new ae_jumping_mt( 25 );
  
  // Generate a few numbers and check
  printf( "******************** Reals in [0, 1)\n" );
  for ( int i = 0 ; i < 5 ; i++ )
  {
    printf( "%f\t\t%f\n", sfmt_genrand_real2( ref ), my_jumping_mt->random() );
  }
  printf( "******************** Integers in [0, 100)\n" );
  for ( int i = 0 ; i < 5 ; i++ )
  {
    printf( "%"PRId32"\t\t", (int32_t)( 100.0 * (((double)sfmt_genrand_uint32( ref )) / MT_RAND_MAX_PLUS_1) ) );
    printf( "%"PRId32"\n", my_jumping_mt->random( 100 ) );
  }
  
  // Jump ahead manually
	start = clock();
  clock_gettime(CLOCK_REALTIME, &deb);
  for ( uint64_t i = 0 ; i < 2000000 ; i++ )
  {
    sfmt_genrand_real2( ref );
  }
  clock_gettime(CLOCK_REALTIME, &fin);
	elapsed = clock() - start;
	elapsed = elapsed * 1000 / CLOCKS_PER_SEC;
  exec = (double) ((fin.tv_nsec - deb.tv_nsec) / 1000);
  printf( " %u:%u %lu:%lu %lu:%lu exec %f microsecond\n", res.tv_sec, res.tv_nsec, deb.tv_sec, deb.tv_nsec, fin.tv_nsec, fin.tv_sec, exec);
  printf( "%f ms\n", elapsed );
  
  // Jump ahead with polynomial method
	start = clock();
  clock_gettime(CLOCK_REALTIME, &deb);
  my_jumping_mt->jump();
  clock_gettime(CLOCK_REALTIME, &fin);
	elapsed = clock() - start;
	elapsed = elapsed * 1000 / CLOCKS_PER_SEC;
  exec = (double) ((fin.tv_nsec - deb.tv_nsec) / 1000);
  printf(" %u:%u %lu:%lu %lu:%lu exec %f microsecond\n", res.tv_sec, res.tv_nsec, deb.tv_sec, deb.tv_nsec, fin.tv_nsec, fin.tv_sec, exec);
  printf( "%f ms\n", elapsed );
  
  
  // Generate a few numbers and check
  printf( "******************** Reals in [0, 1)\n" );
  for ( int i = 0 ; i < 20 ; i++ )
  {
    printf( "%f\t\t%f\n", sfmt_genrand_real2( ref ), my_jumping_mt->random() );
  }
  printf( "******************** Integers in [0, 100)\n" );
  for ( int i = 0 ; i < 20 ; i++ )
  {
    printf( "%"PRId32"\t\t", (int32_t)( 100.0 * (((double)sfmt_genrand_uint32( ref )) / MT_RAND_MAX_PLUS_1) ) );
    printf( "%"PRId32"\n", my_jumping_mt->random( 100 ) );
  }
  
  //~ gzFile* myFile = (gzFile*) gzopen( "prng.ae", "w" );
  //~ my_jumping_mt->save( myFile );
  //~ gzclose( myFile );
  
  //~ // Generate a few numbers and check
  //~ printf( "******************** Reals in [0, 1)\n" );
  //~ for ( int i = 0 ; i < 20 ; i++ )
  //~ {
    //~ printf( "%f\n", my_jumping_mt->random() );
  //~ }
  //~ printf( "******************** Integers in [0, 100)\n" );
  //~ for ( int i = 0 ; i < 20 ; i++ )
  //~ {
    //~ printf( "%"PRId32"\n", my_jumping_mt->random( 100 ) );
  //~ }
  
  //~ gzFile* myOtherFile = (gzFile*) gzopen( "prng.ae", "r" );
  //~ ae_jumping_mt* my_other_jumping_mt = new ae_jumping_mt( myOtherFile );
  //~ gzclose( myOtherFile );
  
  //~ // Generate a few numbers and check
  //~ printf( "******************** Reals in [0, 1)\n" );
  //~ for ( int i = 0 ; i < 20 ; i++ )
  //~ {
    //~ printf( "%f\n", my_other_jumping_mt->random() );
  //~ }
  //~ printf( "******************** Integers in [0, 100)\n" );
  //~ for ( int i = 0 ; i < 20 ; i++ )
  //~ {
    //~ printf( "%"PRId32"\n", my_other_jumping_mt->random( 100 ) );
  //~ }
}
Example #5
0
uint32_t wrap_genrand_uint32(sfmt_t* sfmt) {
  return sfmt_genrand_uint32(sfmt);
}
Example #6
0
int InfGraph::BuildHypergraphNode(int uStart, int hyperiiid, bool addHyperEdge){
    int n_visit_edge=1;
    if(addHyperEdge){
        hyperGT[hyperiiid].push_back(uStart);
    }

    int n_visit_mark=0;

    //hyperiiid ++;
    q.clear();
    q.push_back(uStart);
    visit_mark[n_visit_mark++]=uStart;
    visit[uStart]=true;
    while(!q.empty()) {
        int expand=q.front();
        q.pop_front();
        if(influModel==IC){
            int i=expand;
            for(int j=0; j<(int)gT[i].size(); j++){
                //int u=expand;
                int v=gT[i][j];
                n_visit_edge++;
                double randDouble=double(sfmt_genrand_uint32(&sfmtSeed))/double(RAND_MAX)/2;
                if(randDouble > probT[i][j])
                    continue;
                if(visit[v])
                    continue;
                if(!visit[v])
                {
                    visit_mark[n_visit_mark++]=v;
                    visit[v]=true;
                }
                q.push_back(v);
                //#pragma omp  critical
                //if(0)
                if(addHyperEdge)
                {
                    //hyperG[v].push_back(hyperiiid);
                    hyperGT[hyperiiid].push_back(v);
                }
            }
        }
        else if(influModel==LT){
            if(gT[expand].size()==0)
                continue;
            n_visit_edge+=gT[expand].size();
            double randDouble=double(sfmt_genrand_uint32(&sfmtSeed))/double(RAND_MAX)/2;
            for(int i=0; i<(int)gT[expand].size(); i++){
                randDouble -= probT[expand][i];
                if(randDouble>0)
                    continue;
                //int u=expand;
                int v=gT[expand][i];

                if(visit[v])
                    break;
                if(!visit[v]){
                    visit_mark[n_visit_mark++]=v;
                    visit[v]=true;
                }
                q.push_back(v);
                if(addHyperEdge){
                    hyperGT[hyperiiid].push_back(v);
                }
                break;
            }
        }
    }
    for(int i=0; i<n_visit_mark; i++)
        visit[visit_mark[i]]=false;
    return n_visit_edge;
}