コード例 #1
0
ファイル: perf.test.cpp プロジェクト: wo3kie/assocVector
void random_operations()
{
    for( unsigned i = 100 ; i <= REPS ; i *= 10 )
    {
        std::vector< std::pair< int, int > > array;

        for( unsigned j = 0 ; j < i/2 ; ++ j )
            array.push_back( std::make_pair( 0, my_random() ) );

        for( unsigned j = i/2 ; j < i ; ++ j )
            array.push_back( std::make_pair( my_random( 0, 2 ), my_random() ) );

        test_random_operations< AssocVector< int, _T > >( REPS / i, array, "test_random_operations.AssocVector< int, " + name< _T >() + " >" );

#ifdef AV_TEST_LOKI
        test_random_operations< Loki::AssocVector< int, _T > >( REPS / i, array, "test_random_operations.Loki::AssocVector< int, " + name< _T >() + " >" );
#endif

#ifdef AV_TEST_STD_MAP
        test_random_operations< std::map< int, _T > >( REPS / i, array, "test_random_operations.std::map< int, " + name< _T >() + " >" );
#endif

#ifdef AV_TEST_BOOST_HASH
        test_random_operations< boost::unordered_map< int, _T > >( REPS / i, array, "test_random_operations.boost::map< int, " + name< _T >() + " >" );
#endif

        std::cout << std::endl;
    }
}
コード例 #2
0
bool RtpSession::setup( uint16_t base_port, const char* cname, 
		const char* peer_addr, uint16_t peer_port, 
		uint8_t payload_type, uint32_t rtp_clock )
{
  	if ( rtp_clock == 0 ) {
    		printf("RtpSession: RTPClock is 0.. aborting..\n");
		return false;
  	}

	m_payload_type = payload_type;
	m_rtp_clock = rtp_clock;

	m_ssrc = (uint32_t)my_random();
	m_base_timestamp = (uint32_t)my_random();
	m_base_seq = (uint16_t)my_random();

	m_last_timestamp = m_base_timestamp;
	m_prev_timestamp = m_base_timestamp;
	m_seq = m_base_seq;

	if ( ! create_sockets( base_port ) ) {
		printf("RtpSession: cannot create socket pairs\n");
		return false;
	}
	if ( ! setup_peer( peer_addr, peer_port ) ) {
		printf("RtpSession: cannot setup pear host\n");
		return false;
	}
		
	set_cname( cname );
	
	return true;
}
コード例 #3
0
ファイル: 2048.c プロジェクト: XiangTianxiao/2048
// place_tile() returns 0 if it did place a tile and -1 if there is no open
// space.
int place_tile(struct game_t *game)
{
	// lboard is the "linear board" -- no need to distinguish rows/cols
	tile_t *lboard = (tile_t *)game->board;
	int i, num_zeros = 0;

	// Walk the board and count the number of empty tiles
	for (i = 0; i < NROWS * NCOLS; i++)
	{
		num_zeros += lboard[i] ? 0 : 1;
	}

	if (!num_zeros)
	{
		return -1;
	}

	// Choose the insertion point
	int loc = my_random() % num_zeros;

	// Find the insertion point and place the new tile
	for (i = 0; i < NROWS * NCOLS; i++)
	{
		if (!lboard[i] && !(loc--))
		{
			lboard[i] = my_random() % 10 ? 1 : 2;
			return 0;
		}
	}
	return -1;
}
コード例 #4
0
ファイル: bank_simple.c プロジェクト: respu/libslock
void *test(void *data)
{
  int rand_max;
  thread_data_t *d = (thread_data_t *)data;
  unsigned short seed[3];
  seeds = seed_rand();

//#ifdef __sparc__
    phys_id = the_cores[d->id];
    cluster_id = get_cluster(phys_id);
//#else
//    phys_id = d->id;
//#endif

  /* Initialize seed (use rand48 as rand is poor) */
  seed[0] = (unsigned short)rand_r(&d->seed);
  seed[1] = (unsigned short)rand_r(&d->seed);
  seed[2] = (unsigned short)rand_r(&d->seed);

  rand_max = d->bank->size - 1;

  /* local initialization of locks */
  local_th_data[d->id] = init_lock_array_local(phys_id, d->bank->size, the_locks);

  /* Wait on barrier */
  barrier_cross(d->barrier);

  while (stop == 0) 
    {
      uint32_t nb = (uint32_t) (my_random(&(seeds[0]),&(seeds[1]),&(seeds[2])) % 100);
      uint32_t acc = (uint32_t) my_random(&(seeds[0]),&(seeds[1]),&(seeds[2])) & rand_max;
      account_t* accp = &d->bank->accounts[acc];

      if (nb < d->deposit_perc) 
	{
	  deposit(accp, 1, d->id);
	  d->nb_deposit++;
	} 
      else if (nb < d->withdraw_perc) 
	{
	  withdraw(accp, 1, d->id);
	  d->nb_withdraw++;
	} 
      else	     /* nb < balance_perc */
	{
	  check(accp, d->id);
	  d->nb_balance++;
	}

    }
  /* Free locks */
  //free_local(local_th_data[d->id], d->bank->size);
  return NULL;
}
コード例 #5
0
ファイル: Bubble.cpp プロジェクト: muggenhor/fishtank
Bubble::Bubble(const Aquarium& aquarium, const Eigen::Vector3f& startpos, float radius, bool wiggle) :
	Object(loadModel("", "icosphere-2"), startpos),
	wiggleStartX(my_random() * 100),
	wiggleStartZ(my_random() * 100),
	wiggle(wiggle),
	velocity(-3 + my_random() * 6, 10, -3 + my_random() * 6),
	pop(1 + my_random() * 0.8),
	aquarium(aquarium)
{
	scale = radius;
}
コード例 #6
0
ファイル: masterslave_arg.c プロジェクト: Julio-Anjos/simgrid
/** Main function */
int main(int argc, char *argv[])
{
  msg_error_t res = MSG_OK;
  long i;

  MSG_init(&argc, argv);
  if (argc < 4) {
    printf("Usage: %s platform_file number_of_jobs number_of_slaves\n", argv[0]);
    printf("example: %s msg_platform.xml 10 5\n", argv[0]);
    exit(1);
  }

  MSG_function_register("master", master);
  MSG_function_register("slave", slave);

  MSG_create_environment(argv[1]);

  number_of_jobs = atol(argv[2]);
  number_of_slaves = atol(argv[3]);
  xbt_dynar_t host_dynar = MSG_hosts_as_dynar();
  long number_max = xbt_dynar_length(host_dynar);
  XBT_INFO("Got %ld slaves, %ld tasks to process, and %ld hosts", number_of_slaves, number_of_jobs,number_max);

  msg_host_t *host_table =  xbt_dynar_to_array(host_dynar);
  //xbt_dynar_free(&host_dynar);

  MSG_process_create( "master",
                      master,
                      NULL,
                      host_table[my_random(number_max)]
                      );

  for(i = 0 ; i<number_of_slaves; i++)
  {
    char* name_host = bprintf("slave-%ld",i);
      MSG_process_create( name_host,
                          slave,
                          NULL,
                          host_table[my_random(number_max)]
                          );
      free(name_host);
  }
  xbt_free(host_table);

  res = MSG_main();

  XBT_INFO("Simulation time %g", MSG_get_clock());

  if (res == MSG_OK)
    return 0;
  else
    return 1;
}                               /* end_of_main */
コード例 #7
0
ファイル: serveur_init.c プロジェクト: SylTi/school
void	init_pos(t_env *env, int socket)
{
  char	*str;

  str = NULL;
  env->fd[socket].x = my_random(env->x_world - 1);
  env->fd[socket].y = my_random(env->y_world - 1);
  env->fd[socket].sens = UP;
  env->fd[socket].lvl = 1;
  str = xmalloc(100);
  sprintf(str, "%d %d\n", env->x_world, env->y_world);
  xwrite(socket, str, strlen(str));
  free(str);
}
コード例 #8
0
ファイル: loop_game.c プロジェクト: Francoisbeche/tetris
t_elem		*get_next_tet(t_tetris *t)
{
  t_elem	*tmp;
  int		i;
  int		rand;

  i = 0;
  time(NULL);
  tmp = t->list->tail;
  while (tmp != NULL)
    {
      if (tmp->status == 0)
	i++;
      tmp = tmp->prev;
    }
  rand = my_random(0,(i - 1));
  tmp = t->list->tail;
  i = 0;
  while (i < rand)
    {
      tmp = tmp->prev;
      if (tmp->status == 1)
	tmp = tmp->prev;
      i++;
    }
  return (tmp);
}
コード例 #9
0
// Sample
int powerlaw::sample() {
  if(proba_big!=0 && test_proba(proba_big)) return int(floor(0.5+big_sample(random_float())));
  int r=my_random();
  // table[] contains integer from MY_RAND_MAX downto 0, in blocks. Search block...
  if(r>(MY_RAND_MAX>>max_dt)) return mini;
  int k=0;
  while(k<max_dt) { r<<=1; r+=random_bit(); k++; };
  int a=0;
  int b;
  while((b=dt[k++])<0 || r<table[b]) { 
    if(b>=0) {
      a=b+1;
      if(a==tabulated-1) break;
      r<<=1;
      r+=random_bit();
    }
  }

  // Now that we found the good block, run a dichotomy on this block [a,b]
  while(a<b) {
    int c = (a+b)/2;
    if(r<table[c]) a=c+1;
    else b=c;
  }
  return mini+a;
}
コード例 #10
0
ファイル: ttasepfl.c プロジェクト: multicore-locks/litl
int ttasepfl_mutex_lock(ttasepfl_mutex_t *impl, ttasepfl_context_t *me) {
    volatile uint8_t *l = &(impl->spin_lock);
    uint32_t delay;

    while (1) {
        PREFETCHW(l);
        while ((*l) != UNLOCKED) {
            PREFETCHW(l);
        }
        if (l_tas_uint8(&(impl->spin_lock)) == UNLOCKED) {
#if COND_VAR
            int ret = REAL(pthread_mutex_lock)(&impl->posix_lock);
            assert(ret == 0);
#endif
            return 0;
        } else {
            // backoff
            delay = my_random(&(ttas_seeds[0]), &(ttas_seeds[1]),
                              &(ttas_seeds[2])) %
                    (me->limit);
            me->limit =
                MAX_DELAY > 2 * (me->limit) ? 2 * (me->limit) : MAX_DELAY;
            cdelay(delay);
        }
    }
}
コード例 #11
0
ファイル: skill.cpp プロジェクト: lindianyin/sgbj
int baseSkillMgr::updateTeacher(int mapid, boost::shared_ptr<skillTeacher>* teachers)
{
    //cout<<"updateTeacher:"<<mapid<<endl;
    int max_teacher_id = 4 * mapid;
    if (max_teacher_id <= 0)
    {
        max_teacher_id = 4;
    }
    else if (max_teacher_id > (int)m_base_skillsTeachers.size())
    {
        max_teacher_id = m_base_skillsTeachers.size();
    }
    std::vector<boost::shared_ptr<skillTeacher> > teachers_maps;
    for (int i = 1; i <= max_teacher_id; ++i)
    {
        teachers_maps.push_back(m_base_skillsTeachers[i]);
    }
    for (int i = 0; i < skill_teacher_nums; ++i)
    {
        //cout<<"random 1 - "<<teachers_maps.size()<<" result ";
        int idx = my_random(1, teachers_maps.size());
        //cout<<idx<<endl;
        teachers[i].reset();
        teachers[i] = teachers_maps[idx - 1];
        teachers_maps.erase(teachers_maps.begin() + idx - 1);
    }
    return HC_SUCCESS;
}
コード例 #12
0
ファイル: perf.test.cpp プロジェクト: wo3kie/assocVector
void index_operator_random()
{
    for( unsigned i = 100 ; i <= REPS ; i *= 10 )
    {
        std::vector< int > array;

        for( unsigned j = 0 ; j < i ; ++ j )
            array.push_back( my_random() );

        test_index_operator_random< AssocVector< int, _T > >( REPS / i, array, "index_operator_random.AssocVector< int, " + name< _T >() + " >" );

#ifdef AV_TEST_LOKI
        test_index_operator_random< Loki::AssocVector< int, _T > >( REPS / i, array, "index_operator_random.Loki::AssocVector< int, " + name< _T >() + " >" );
#endif

#ifdef AV_TEST_STD_MAP
        test_index_operator_random< std::map< int, _T > >( REPS / i, array, "index_operator_random.std::map< int, " + name< _T >() + " >" );
#endif

#ifdef AV_TEST_BOOST_HASH
        test_index_operator_random< boost::unordered_map< int, _T > >( REPS / i, array, "index_operator_random.boost::map< int, " + name< _T >() + " >" );
#endif

        std::cout << std::endl;
    }
}
コード例 #13
0
StkFloat Shakers :: ratchet_tick() {
  StkFloat data;
  if (my_random(1024) < nObjects_) {
    sndLevel_ += 512 * ratchet_ * totalEnergy_;
  }
  inputs_[0] = sndLevel_;
  inputs_[0] *= noise_tick() * ratchet_;
  sndLevel_ *= soundDecay_;
		 
  inputs_[1] = inputs_[0];
  inputs_[0] -= outputs_[0][0]*coeffs_[0][0];
  inputs_[0] -= outputs_[0][1]*coeffs_[0][1];
  outputs_[0][1] = outputs_[0][0];
  outputs_[0][0] = inputs_[0];
  inputs_[1] -= outputs_[1][0]*coeffs_[1][0];
  inputs_[1] -= outputs_[1][1]*coeffs_[1][1];
  outputs_[1][1] = outputs_[1][0];
  outputs_[1][0] = inputs_[1];
     
  finalZ_[2] = finalZ_[1];
  finalZ_[1] = finalZ_[0];
  finalZ_[0] = gains_[0]*outputs_[0][1] + gains_[1]*outputs_[1][1];
  data = finalZ_[0] - finalZ_[2];
  return data;
}
コード例 #14
0
StkFloat Shakers :: tbamb_tick() {
  StkFloat data, temp;
  static int which = 0;
  int i;

  if (shakeEnergy_ > MIN_ENERGY)	{
      shakeEnergy_ *= systemDecay_;    // Exponential system decay
      if (float_random(1024.0) < nObjects_) {
	    sndLevel_ += shakeEnergy_;
	    which = my_random(7);
	  }  
      temp = sndLevel_ * noise_tick();      // Actual Sound is Random
	  for (i=0;i<nFreqs_;i++)	inputs_[i] = 0;
	  inputs_[which] = temp;
      sndLevel_ *= soundDecay_;                   // Exponential Sound decay 
      finalZ_[2] = finalZ_[1];
      finalZ_[1] = finalZ_[0];
      finalZ_[0] = 0;
      for (i=0;i<nFreqs_;i++)	{
        inputs_[i] -= outputs_[i][0]*coeffs_[i][0];  // Do
        inputs_[i] -= outputs_[i][1]*coeffs_[i][1];  // resonant
        outputs_[i][1] = outputs_[i][0];            // filter
        outputs_[i][0] = inputs_[i];                // calculations
        finalZ_[0] += gains_[i] * outputs_[i][1];
      }
      data = finalZCoeffs_[0] * finalZ_[0];     // Extra zero(s) for shape
      data += finalZCoeffs_[1] * finalZ_[1];    // Extra zero(s) for shape
      data += finalZCoeffs_[2] * finalZ_[2];    // Extra zero(s) for shape
      if (data > 10000.0)	data = 10000.0;
      if (data < -10000.0) data = -10000.0;
      data = data * 0.0001;
  }
  else data = 0.0;
  return data;
}
コード例 #15
0
ファイル: guiro~.c プロジェクト: dsholmes/PeRColate
float guiro_tick(t_guiro *x) {
  float data;
  if (my_random(1024) < x->num_objects) {
    x->sndLevel += 512. * x->ratchet * x->totalEnergy;
  }
  x->input = x->sndLevel;
  x->input *= noise_tick() * x->ratchet;
  x->sndLevel *= x->soundDecay;
		 
  x->input2 = x->input;
  x->input -= x->output[0]*x->coeffs[0];
  x->input -= x->output[1]*x->coeffs[1];
  x->output[1] = x->output[0];
  x->output[0] = x->input;
  x->input2 -= x->output2[0]*x->coeffs2[0];
  x->input2 -= x->output2[1]*x->coeffs2[1];
  x->output2[1] = x->output2[0];
  x->output2[0] = x->input2;
     
  x->finalZ[2] = x->finalZ[1];
  x->finalZ[1] = x->finalZ[0];
  x->finalZ[0] = x->output[1] + x->output2[1];
  data = x->finalZ[0] - x->finalZ[2];
		
  return data;
}
コード例 #16
0
ファイル: sbj.c プロジェクト: ftnapps/pkg-sbbs
void shuffle()
{
	char str[81];
	uint i,j;
	card_t shufdeck[52*MAX_DECKS];


getcarddat();

sprintf(str,"\1_\1w\1h\r\nShuffling %d Deck Shoe...",total_decks);
bputs(str);
strcat(str,"\r\n");     /* add crlf for other nodes */
putallnodemsg(str);

for(i=0;i<total_decks;i++)
	memcpy(shufdeck+(i*52),newdeck,sizeof(newdeck));	  /* fresh decks */

i=0;
while(i<(uint)(total_decks*52)-1) {
	j=my_random((total_decks*52)-1);
	if(!shufdeck[j].value)	/* card already used */
		continue;
	card[i]=shufdeck[j];
	shufdeck[j].value=0;	/* mark card as used */
	i++; }

cur_card=0;
for(i=0;i<MAX_HANDS;i++)
	pc[i]=0;
hands=0;
dc=0;
putcarddat();
bputs("\r\n");
}
コード例 #17
0
ファイル: perf.test.cpp プロジェクト: wo3kie/assocVector
void insert_random()
{
    for( unsigned i = 100 ; i <= REPS ; i *= 10 )
    {
        std::vector< int > array;

        for( unsigned j = 0 ; j < i ; ++ j )
            array.push_back( my_random() );

        test_insert_random< AssocVector< int, _T > >( REPS / i, array, "insert_random.AssocVector< int, " + name< _T >() + " >" );

#ifdef AV_TEST_EXTENSIONS
        test__insert_random< AssocVector< int, _T > >( REPS / i, array, "    _insert_random.AssocVector< int, " + name< _T >() + " >" );
#endif

#ifdef AV_TEST_VECTOR
        //test_insert_random_push_back_sort< std::vector< std::pair< int, _T > > >( REPS / i, array, "    insert_random.std::vector< int, _T >.push_back.sort" );
#endif

#ifdef AV_TEST_LOKI
        test_insert_random< Loki::AssocVector< int, _T > >( REPS / i, array, "insert_random.Loki::AssocVector< int, " + name< _T >() + " >" );
#endif

#ifdef AV_TEST_STD_MAP
        test_insert_random< std::map< int, _T > >( REPS / i, array, "insert_random.std::map< int, " + name< _T >() + " >" );
#endif

#ifdef AV_TEST_BOOST_HASH
        test_insert_random< boost::unordered_map< int, _T > >( REPS / i, array, "insert_random.boost::map< int, " + name< _T >() + " >" );
#endif

        std::cout << std::endl;
    }
}
コード例 #18
0
ファイル: perf.test.cpp プロジェクト: wo3kie/assocVector
    S3()
    {
        ++ createdObjects;

        for( int i = 0 ; i < 10 ; ++ i ){
            array.push_back( my_random() );
        }
    }
コード例 #19
0
ファイル: agent.cpp プロジェクト: aijunbai/reversi
inline int Agent::random_to_put()
{
	int pos;
	for(;;){
		pos = my_random()%64 + 1;
		if( board->can_put( pos, role))
			break;
	}
	return pos;
}
コード例 #20
0
ファイル: battle.cpp プロジェクト: tvo/springlobby
void shuffle(std::vector<User *> &players) // proper shuffle.
{
    for ( size_t i=0; i < players.size(); ++i ) // the players below i are shuffled, the players above arent
    {
        int rn = i + my_random( players.size() - i ); // the top of shuffled part becomes random card from unshuffled part
        User *tmp = players[i];
        players[i] = players[rn];
        players[rn] = tmp;
    }
}
コード例 #21
0
ファイル: logging.cpp プロジェクト: metiscus/microgear
void log_ap( uint8_t *buf, int size, int skip_count ) {
    if ( skip_count < 0 ) { skip_count = 0; }
    static uint8_t skip = my_random(skip_count);

    if ( skip > 0 ) {
        --skip;
        return;
    } else {
        skip = skip_count;
    }

    gzwrite( fap, buf, size );
}
コード例 #22
0
ファイル: book.cpp プロジェクト: ZirconiumX/fruitfly
int book_move(board_t * board) {

   int best_move;
   int best_score;
   int pos;
   entry_t entry[1];
   int move;
   int score;
   list_t list[1];
   int i;

   ASSERT(board!=NULL);

   if (BookFile != NULL && BookSize != 0) {

      // draw a move according to a fixed probability distribution

      best_move = MoveNone;
      best_score = 0;

      for (pos = find_pos(board->key); pos < BookSize; pos++) {

         read_entry(entry,pos);
         if (entry->key != board->key) break;

         move = entry->move;
         score = entry->count;

         // pick this move?

         ASSERT(score>0);

         best_score += score;
         if (my_random(best_score) < score) best_move = move;
      }

      if (best_move != MoveNone) {

         // convert PolyGlot move into Fruit move; TODO: handle promotes

         gen_legal_moves(list,board);

         for (i = 0; i < list->size; i++) {
            move = list->move[i];
            if ((move & 07777) == best_move) return move;
         }
      }
   }

   return MoveNone;
}
コード例 #23
0
void *test(void *data)
{
    int rand_max;
    thread_data_t *d = (thread_data_t *)data;
    uint64_t res;
    phys_id= the_cores[d->id];
    set_cpu(phys_id);

    seeds = seed_rand();
    rand_max = num_entries - 1;

    /* Init of local data if necessary */

    /* Wait on barrier */
    barrier_cross(d->barrier);
    int entry;

    while (stop == 0) {
        if (num_entries==1) {
            entry=0;
        } else {
            entry =(int) my_random(&(seeds[0]),&(seeds[1]),&(seeds[2])) & rand_max;
        }
        //   entry = (int)(erand48(seed) * rand_max) + rand_min;
#ifdef TEST_CAS
        do {
            res = CAS_U8(&(the_data[entry].data),0,1);
        } while(res!=0);
#elif defined(TEST_TAS)
        do {
            res = TAS_U8(&(the_data[entry].data));
        } while (res!=0);
#elif defined(TEST_FAI)
        FAI_U8(&(the_data[entry].data));
#else
        perror("No test primitive specified");
#endif 
        MEM_BARRIER;
        the_data[entry].data = 0;
        d->num_operations++;
        if (op_pause>0) {
            cpause(op_pause);
        }
    }

    /* Free any local data if necessary */ 

    return NULL;
}
コード例 #24
0
ファイル: ttas.c プロジェクト: YunlongXu/tm-study-pact14
void ttas_lock(ttas_lock_t * the_lock, uint32_t* limit) {
    uint32_t delay;
    volatile ttas_lock_data_t* l = &(the_lock->lock);
    while (1){
        while ((*l)==1) {}
        if (CAS_U8(l,UNLOCKED,LOCKED)==UNLOCKED) {
            return;
        } else {
            //backoff
            delay = my_random(&(ttas_seeds[0]),&(ttas_seeds[1]),&(ttas_seeds[2]))%(*limit);
            *limit = MAX_DELAY > 2*(*limit) ? 2*(*limit) : MAX_DELAY;
            cdelay(delay);
        }
    }
}
コード例 #25
0
ファイル: Random.c プロジェクト: bangbh81/MbedTLS-Test
/*
	Function£º
			Create a Pseudo-random number value 
	Parameters£º
	      
	Return Value£º
		0 -- Success
		1 -- Fail

*/
int my_drbg_random( void *p_rng, unsigned char *output, int output_len )
{
    int i;

	if(output_len <= 0)
	{
         return (1);
	}
    for(i = 0;i < output_len;i++)
    {
       *output++ = my_random(100);
	}
	
	return (0);
}
コード例 #26
0
float cabasa_tick(t_cabasa *x) {
  float data;
  x->shakeEnergy *= x->systemDecay;         	// Exponential system decay
  if (my_random(1024) < x->num_objects)  		// If collision
  	x->sndLevel += x->gain * x->shakeEnergy;   	//   add energy
  x->input = x->sndLevel * noise_tick();    	// Actual Sound is Random
  x->sndLevel *= x->soundDecay;             	// Exponential Sound decay 
  x->input -= x->output[0]*x->coeffs[0];       	// Do gourd
  x->input -= x->output[1]*x->coeffs[1];       	//   resonance
  x->output[1] = x->output[0];              	//     filter
  x->output[0] = x->input;                  	//       calculations
  data = x->output[0] - x->output[1];
		
  return data;
}
コード例 #27
0
ファイル: demo3.c プロジェクト: AsamQi/levawc
/* --- void queue_elements(Queue que, int nr_of_ele) --- */
void queue_elements(Queue que, int nr_of_ele)
{
  int i=0, *pi, retval;

  do
    {
      pi = (int *)malloc(sizeof(int));
      *pi = my_random(1,50);
      retval = QUEUEenqueue(que, pi);
      assert(retval == OK);
    } while (++i < nr_of_ele);

  printf("\nCurrent queue content(%d elements): ", QUEUEsize(que));
  /* This call to SLISTtraverse is possible - although this function is NOT a member
     of the queue (public) interface - but because a queue is also a list ! */
  SLISTtraverse(que, print, SLIST_FWD);
}
コード例 #28
0
ファイル: rw_ttas.c プロジェクト: YunlongXu/tm-study-pact14
void write_acquire(rw_ttas* lock, uint32_t* limit) {
    uint32_t delay;
    while (1)
    {
        while (lock->lock_data!=0)
        {
        }
        if (CAS_U16(&lock->lock_data,0,W_MASK)==0) {
            return;
        }
        else {
            delay = my_random(&(rw_seeds[0]),&(rw_seeds[1]),&(rw_seeds[2]))%(*limit);
            *limit = MAX_DELAY > 2*(*limit) ? 2*(*limit) : MAX_DELAY;
            cdelay(delay);
        }

    }
}
コード例 #29
0
void Peptide::generate_random_peptide(const Config *config, int peptide_length)
{
	amino_acids.clear();
	n_gap=0;

	int i;

//	n_term = N_TERM;
//	c_term = C_TERM;

	mass=0;
	for (i=0; i<peptide_length; i++)
	{
		int aa = Ala + (int)(my_random() * (Val-Ala));
		mass += config->get_aa2mass()[aa];
		amino_acids.push_back(aa);
	}
}
コード例 #30
0
ファイル: rw_ttas.c プロジェクト: YunlongXu/tm-study-pact14
void read_acquire(rw_ttas* lock, uint32_t* limit) {
    uint32_t delay;
    while (1)
    {
        rw_data_t aux;
        while ((aux=lock->lock_data)>MAX_RW)
        {
        }
        //uint16_t aux = (uint16_t) lock->lock_data;
        if (CAS_U16(&lock->lock_data,aux,aux+1)==aux) {
            return;
        }
        else 
        {
            delay = my_random(&(rw_seeds[0]),&(rw_seeds[1]),&(rw_seeds[2]))%(*limit);
            *limit = MAX_DELAY > 2*(*limit) ? 2*(*limit) : MAX_DELAY;
            cdelay(delay);
        }
    }
}