コード例 #1
0
static void connect_rooms(cell_t *cell_arr, room_t *room_arr, int num_room)
{
  int i, x, y;
  path_node_c_t *path_arr, *curr_p;
  heap_t *h;
  room_t *room;

  h = (heap_t *) malloc(sizeof(*h));

  for(i = 1; i < num_room; i++)
    {
      room = room_arr + i;
      x = random_number(room->x, room->x + room->width - 1);
      y = random_number(room->y, room->y + room->height - 1);
   
      heap_init(h, gen_path_node_cmp, NULL);
      path_arr = (path_node_c_t *) malloc(MAP_HEIGHT * MAP_WIDTH *
				  sizeof(*path_arr));
      initialize_heap(h, path_arr, cell_arr);
           
      curr_p = path_arr + (MAP_WIDTH * y) + x;
      curr_p->weight = 1;
      curr_p->distance = 0;
      curr_p->previous = NULL;
      heap_decrease_key_no_replace(h, curr_p->heap_node);

      create_corridor(h, path_arr);

      room = room_arr + i - 1;
      x = random_number(room->x, room->x + room->width - 1);
      y = random_number(room->y, room->y + room->height - 1);
      curr_p = path_arr + (MAP_WIDTH * y) + x;

      place_corridor(curr_p, cell_arr);

      heap_delete(h);
      free(path_arr);
    }
  
  free(h);
}
コード例 #2
0
void updateWorld()
{
	for(int n = 0; n < (0.5*P.N); ++n)
	{
		//pick a random cell
		int x = random_number(P.sizeX);
		int y = random_number(P.sizeY);
		bool picked_viable = (bool)viable[x][y];
		while(picked_viable == false)
		{
			x = random_number(P.sizeX);
			y = random_number(P.sizeY);
			picked_viable = (bool)viable[x][y];
		}


		//species at x,y dies and gets replaced
		//with prob 1-m it is from within the local community
		if(uniform() < P.m) //migration
		{
			species migrant = getSpeciesFromMetaCommunity();
			world[x][y] = migrant;
		}
		else //no migration, local reproduction
		{
			int otherX = x; int otherY = y;
			if(P.dispersalType == "Square") findParent_Square(otherX,otherY,x,y); //square
			else if(P.dispersalType == "Circle") findParent_Circle(otherX,otherY,x,y); //circle
//			else if(P.dispersalType == "Reflect") findParent_Reflect(otherX,otherY,x,y);
			else findParent_Circle(otherX,otherY,x,y);  //default


			world[x][y] = world[otherX][otherY];
			reproduction[otherX][otherY]++;
			//world[x][y] = world[otherX][otherY];


			if(uniform() < P.speciationRate) world[x][y] = newSpecies();
		}
	}
}
コード例 #3
0
ファイル: efuns_port.c プロジェクト: Yuffster/fluffOS
void
f_oldcrypt (void) {
    char *res, salt[3];
    const char *choice =
    "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ./";

    if (sp->type == T_STRING && SVALUE_STRLEN(sp) >= 2) {
        salt[0] = sp->u.string[0];
        salt[1] = sp->u.string[1];
        free_string_svalue(sp--);
    } else {
        salt[0] = choice[random_number(strlen(choice))];
        salt[1] = choice[random_number(strlen(choice))];
        pop_stack();
    }
    salt[2] = 0;
    res = string_copy(OLDCRYPT(sp->u.string, salt), "f_crypt");
    free_string_svalue(sp);
    sp->subtype = STRING_MALLOC;
    sp->u.string = res;
}
コード例 #4
0
ファイル: dwlib.c プロジェクト: Yuffster/fluffOS
void
f_roll_MdN() {
   long roll = 0;

   if ( (sp - 1)->u.number > 0 && sp->u.number > 0 ) {
      while( (sp - 1)->u.number-- )
         roll += 1 + random_number( sp->u.number );
   }

   pop_stack();            // Pop one...
   sp->u.number = roll;    // And change the other!
}
コード例 #5
0
ファイル: Blocks.cpp プロジェクト: Coguar/TP
void update(RenderWindow & window, Group & group) {
	if (group.location == 1) {
		group.direction = random_number(4);
		group.efect_number = random_number(3);
		group.location++;
	}
	if (group.location == 2) {
		switch (group.direction)
		{
		case 1: group.left(); break;
		case 2: group.right(); break;
		case 3: group.up(); break;
		case 4: group.down(); break;
		}
		switch (group.efect_number)
		{
		case 1: group.effect_color(); break;
		case 2: group.effect_rotate(); break;
		case 3: group.effect_size(); break;
		}

	}
	if (group.location == 3) {

		switch (group.efect_number)
		{
		case 1: group.effect_color(); break;
		case 2: group.effect_rotate(); break;
		case 3: group.effect_size(); break;
		}

		switch (group.direction)
		{
		case 1: group.back_from_left(); break;
		case 2: group.back_from_right(); break;
		case 3: group.back_from_up(); break;
		case 4: group.back_from_down(); break;
		}
	}
}
コード例 #6
0
ファイル: test_hash_set.cpp プロジェクト: hoangduit/reactos
void test_hash_set()
{
# if !(defined (_MSC_VER) && (_MSC_VER < 1100))
  TestSet testSet, testSet2;

        const size_t hash_setSize = random_number(random_base);

  while ( testSet.size() < hash_setSize )
  {
    TestSet::value_type x;
    testSet.insert( x );
    testSet2.insert( TestSet::value_type() );
  }

#  if defined( EH_HASH_CONTAINERS_SUPPORT_RESIZE )
  WeakCheck( testSet, test_hash_resize<TestSet>() );
  // TestMultiSet == TestMultiSet: no such operator! - ptr
  // StrongCheck( testSet, test_insert_noresize<TestSet>(testSet) );
#  endif
  WeakCheck( testSet, test_insert_value<TestSet>(testSet) );

  size_t insCnt = random_number(random_base);
  TestSet::value_type *insFirst = new TestSet::value_type[1+insCnt];
  WeakCheck( testSet, insert_range_tester(testSet, insFirst, insFirst+insCnt) );
  ConstCheck( 0, test_construct_pointer_range<TestSet>(insFirst, insFirst+insCnt) );
  delete[] insFirst;

  WeakCheck( testSet, insert_range_tester(testSet, testSet2.begin(), testSet2.end() ) );

  ConstCheck( 0, test_default_construct<TestSet>() );
#  if EH_HASH_CONTAINERS_SUPPORT_ITERATOR_CONSTRUCTION
  ConstCheck( 0, test_construct_iter_range_n<TestSet>( testSet2 ) );
#  endif
  ConstCheck( testSet, test_copy_construct<TestSet>() );

  WeakCheck( testSet, test_assign_op<TestSet>( testSet2 ) );
# endif
}
コード例 #7
0
void test_deque()
{
    EH_STD::size_t dequeSize = random_number(random_base);
    TestDeque emptyDeque;
    TestDeque testDeque, testDeque2;
    while ( testDeque.size() < dequeSize )
    {
        DQTestClass x;
        testDeque.push_back( x );
        testDeque2.push_back( DQTestClass() );
    }

    ConstCheck( testDeque, test_copy_construct<TestDeque>() );
    WeakCheck( testDeque, test_insert_one<TestDeque>(testDeque) );
    StrongCheck( testDeque, test_insert_one<TestDeque>(testDeque,0) );
    StrongCheck( testDeque, test_insert_one<TestDeque>(testDeque, testDeque.size()) );

    WeakCheck( testDeque, test_insert_n<TestDeque>(testDeque, random_number(random_base) ) );
    StrongCheck( testDeque, test_insert_n<TestDeque>(testDeque, random_number(random_base), 0 ) );
    StrongCheck( testDeque, test_insert_n<TestDeque>(testDeque, random_number(random_base), testDeque.size() ) );

    EH_STD::size_t insCnt = random_number(random_base);
    DQTestClass *insFirst = new TestDeque::value_type[insCnt+1];

    WeakCheck( testDeque, insert_range_tester(testDeque, (DQTestClass *)insFirst, 
					      insFirst+insCnt) );
    StrongCheck( testDeque, insert_range_at_begin_tester(testDeque, (DQTestClass *)insFirst,
							 insFirst+insCnt) );
    StrongCheck( testDeque, insert_range_at_end_tester(testDeque, (DQTestClass *)insFirst, 
						       insFirst+insCnt) );

    ConstCheck( 0, test_construct_pointer_range<TestDeque>( (DQTestClass *)insFirst, 
							    insFirst+insCnt ) );
    delete[] insFirst;

    WeakCheck( testDeque, insert_range_tester(testDeque, testDeque2.begin(), testDeque2.end() ) );

    StrongCheck( testDeque, test_push_back<TestDeque>(testDeque) );
    StrongCheck( emptyDeque, test_push_back<TestDeque>(emptyDeque) );
    StrongCheck( testDeque, test_push_front<TestDeque>(testDeque) );
    StrongCheck( emptyDeque, test_push_front<TestDeque>(emptyDeque) );


    ConstCheck( 0, test_default_construct<TestDeque>() );
    ConstCheck( 0, test_construct_n<TestDeque>( random_number(random_base) ) );
    ConstCheck( 0, test_construct_n_instance<TestDeque>( random_number(random_base) ) );
    ConstCheck( 0, test_construct_iter_range<TestDeque>( testDeque2 ) );

    testDeque2.resize( testDeque.size() * 3 / 2 );
    WeakCheck( testDeque, test_assign_op<TestDeque>( testDeque2 ) );
    testDeque2.resize( testDeque.size() * 2 / 3 );
    WeakCheck( testDeque, test_assign_op<TestDeque>( testDeque2 ) );
}
コード例 #8
0
blueParticle::blueParticle(float x, float y, float dirx, float diry,GameState *state) : Particle(dirx,diry,state)
{	
	Load(state->getApp()->gettextureManager().Get("Content/particle.png"));

	_colour = sf::Color(139,137,137,180);

	SetPosition(x,y);

	life_time_ = random_number( 0.08f, 0.3f );

	direction = sf::Vector2f(dirx,diry);

	speed = rand() % 40 + 90;     // v2 in the range 1 to 100
}
コード例 #9
0
ファイル: pollardrho.cpp プロジェクト: carlosTJunior/ECDLP
int init_branches(Triple *branches,
                  const EllipticCurve ec,
                  const Point P, 
                  const Point Q)
{
    BigInt aj, bj;
    int i;

    for(i = 0; i < L; i++) {
        Point Rj, Ptemp, Qtemp;

        aj = random_number(ec.order);
        bj = random_number(ec.order);
        ecc_mul(Ptemp, ec, aj, P);
        ecc_mul(Qtemp, ec, bj, Q);
        ecc_add(Rj, ec, Ptemp, Qtemp);
        branches[i].c = aj;
        branches[i].d = bj;
        branches[i].point = Rj;
    }

    return 0;
}
コード例 #10
0
planets * starSystem::distributePlanetaryMasses(double inner_dust, double outer_dust)
{
	double
		a,
		e,
		mass,
		crit_mass,
		planetesimal_inner_bound,
		planetesimal_outer_bound;

	dust_bands* dust_head=new dust_bands(inner_dust,outer_dust);
	planets *planet_head=0;
	planets *&temp=planet_head;
	isDustLeft=TRUE;
	cloudEccentricity=0.2;

	planetesimal_inner_bound = innermost_planet(starMass);
	planetesimal_outer_bound = outermost_planet(starMass);

	while (isDustLeft)
	{
		a = random_number(planetesimal_inner_bound,planetesimal_outer_bound);
		e = random_eccentricity( );
		mass = PROTOPLANET_MASS;
#ifdef VERBOSE
		printf("Checking %10f AU:  ",a);
#endif
		if (dust_head->dustAvailable(inner_effect_limit(a, e, mass),outer_effect_limit(a, e, mass)))
		{
#ifdef VERBOSE
			printf(".. Injecting protoplanet.\n");
#endif
			assert(a>0.0);
			dustDensity = DUST_DENSITY_COEFF * sqrt(starMass) * exp(-ALPHA * pow(a,(1.0 / N)));
			crit_mass = critical_limit(a,e,starLuminosity);
			accreteDust(dust_head,mass,a,e,crit_mass,planetesimal_inner_bound,planetesimal_outer_bound);

			if ((mass != 0.0) && (mass != PROTOPLANET_MASS))
				coalescePlanetesimals(planet_head,dust_head,a,e,mass,crit_mass,
						planetesimal_inner_bound,planetesimal_outer_bound);
#ifdef VERBOSE
			else printf(".. failed due to large neighbor.\n");
#endif
		}
#ifdef VERBOSE
		else printf(".. failed.\n");
#endif
	}
	return temp;
}
コード例 #11
0
ファイル: npc.cpp プロジェクト: wacharyzilson/rogue_like_game
npc::npc(cell_t *cell_arr, room_t *room_arr, int num_room, int seq)
{
  traits = 0;
  choose_traits();

  turn = 0;
  seen_x = 150;
  seen_y = 150;
  sequence = seq;

  speed = random_number(5, 20);

  place_monster(cell_arr, room_arr, num_room);
}
コード例 #12
0
static void random_string(int length, char *str) {
    int i;
    int char_type;

    for (i = 0; i < length; i++) {
        char_type = (int) (3 * (rand() / (RAND_MAX + 1.0)));

        switch (char_type) {
            case 0:
                str[i] = random_letter(0);
                break;
            case 1:
                str[i] = random_letter(1);
                break;
            case 2:
                str[i] = random_number();
                break;
            default:
                str[i] = random_number();
                break;
        }
    }
}
コード例 #13
0
Vec refraction_reflection(const Vec &x , int depth, const Sphere &sph, const Ray &r, const Vec &n, const Vec &f, const Vec &nl){
	Ray ray_refraction; 
  ray_refraction.origin= x; 
  ray_refraction.direction= r.direction-n*2*dot(n,r.direction);    


  double r_index_air=1, r_index_glass=1.5;
  double r_index, ddn=dot(r.direction,nl), cos2t=0;
  double temp111, temp112;
  if(dot(n,nl)>0){
  	r_index = r_index_air/r_index_glass;
  	temp111 = 1;
  }
  else {
  	r_index = r_index_glass/r_index_air;
  	temp111 = -1;
  }

  Vec tdir = norm((r.direction*r_index - n*((temp111)*(ddn*r_index+sqrt(cos2t)))));

  if(dot(n,nl)>0){
  	temp112 = -ddn;
  }
  else {
  	temp112 = dot(tdir,n);
  }
  
  double a=r_index_glass-r_index_air;
  double b=r_index_glass+r_index_air;
  double c = 1-(temp112);
  double R0=a*a/(b*b), Re=R0+(1-R0)*c*c*c*c*c,Tr=1-Re,P=.25+.5*Re,RP=Re/P,TP=Tr/(1-P);
  Ray rr3; 
  rr3.origin = x; 
  rr3.direction =tdir;

  Vec temp_vector;
  if(depth>2){
    if(random_number()<P){
      temp_vector = calculate_light(ray_refraction,depth)*RP;
    }
    else{
      temp_vector = calculate_light(rr3,depth)*TP;
    }
  }
  else{
    temp_vector = calculate_light(ray_refraction,depth)*Re+calculate_light(rr3,depth)*Tr;
  }
  return sph.light + mult(f,temp_vector);

}
コード例 #14
0
ファイル: zz_camera_follow.cpp プロジェクト: eaglescv/znzin
bool zz_camera_follow::apply_shake (zz_time diff_time)
{
	if (shake_lifetime == 0) return false;

	if (shake_lifetime <= diff_time) {
		shake_lifetime = 0; // do not modify
		return true;
	}
	else {
		shake_lifetime -= diff_time;
	}

	vec3 shakeed_cam_pos, shakeed_target_pos;

	vec3 shake_min_shrinked(shake_min), shake_max_shrinked(shake_max);

	shakeed_cam_pos = random_number(final_.camera_pos + shake_min_shrinked, final_.camera_pos + shake_max_shrinked);
	shakeed_target_pos = random_number(last_.target_pos + shake_min_shrinked, last_.target_pos + shake_max_shrinked);

	look_at(shakeed_cam_pos, shakeed_target_pos, vec3(0, 0, 1));

	return true;
}
コード例 #15
0
int main()
{
    set_random_limit(1000);
    clock_t tbeg = clock();
    int i = 1;
    while(true) {
        int tm = random_number();
        std::cout<<"["<<i<<"]\t"<<tm<<"\t";
        ++i;
        if (i>1000) break;
        tm = random_number();
        std::cout<<"["<<i<<"]\t"<<tm<<"\t";
        tm = random_number();
        ++i;
        if (i>1000) break;
        std::cout<<"["<<i<<"]\t"<<tm<<"\n";
        ++i;
        if (i>1000) break;
    }
    clock_t tend = clock();
    std::cout<<"______________\ntakes "<<static_cast<double>(tend-tbeg)/CLOCKS_PER_SEC
             <<" seconds\n";
    return 0;
}
コード例 #16
0
ファイル: test_rope.cpp プロジェクト: 3runo5ouza/rhodes
void test_rope()
{
    TestRope testRope, testRope2;
    size_t ropeSize = random_number(random_base);

    while ( testRope.size() < ropeSize )
    {
        TestRope::value_type x = TestRope::value_type(random_number(random_base));  // initialize before use
        testRope.push_back( x );
        testRope2.push_back( TestRope::value_type() );
    }
    WeakCheck( testRope, test_insert_one<TestRope>(testRope) );
    WeakCheck( testRope, test_insert_one<TestRope>(testRope, 0) );
    WeakCheck( testRope, test_insert_one<TestRope>(testRope, (int)testRope.size()) );

    WeakCheck( testRope, test_insert_n<TestRope>(testRope, random_number(random_base) ) );
    WeakCheck( testRope, test_insert_n<TestRope>(testRope, random_number(random_base), 0 ) );
    WeakCheck( testRope, test_insert_n<TestRope>(testRope, random_number(random_base), (int)testRope.size() ) );

    size_t insCnt = random_number(random_base);
    TestRope::value_type *insFirst = new TestRope::value_type[1+insCnt];

    WeakCheck( testRope, insert_range_tester(testRope, insFirst, insFirst+insCnt) );
    WeakCheck( testRope, insert_range_at_begin_tester(testRope, insFirst, insFirst+insCnt) );
    WeakCheck( testRope, insert_range_at_end_tester(testRope, insFirst, insFirst+insCnt) );

    ConstCheck( 0, test_construct_pointer_range<TestRope>(insFirst, insFirst+insCnt) );
    delete[] insFirst;

    WeakCheck( testRope, insert_range_tester(testRope, testRope2.begin(), testRope2.end() ) );

    WeakCheck( testRope, test_push_front<TestRope>(testRope) );
    WeakCheck( testRope, test_push_back<TestRope>(testRope) );

    ConstCheck( 0, test_default_construct<TestRope>() );

// dwa 1/25/00 - not actually valid for rope, because it doesn't
// have the constructor in question! The code will compile, but with the
// wrong result (the constructor that gets used does something different).

//  ConstCheck( 0, test_construct_n<TestRope>( random_number(random_base) ) );

    ConstCheck( 0, test_construct_n_instance<TestRope>( random_number(random_base) ) );
    ConstCheck( 0, test_construct_iter_range<TestRope>( testRope2 ) );
    ConstCheck( testRope, test_copy_construct<TestRope>() );

    WeakCheck( testRope, test_assign_op<TestRope>( testRope2 ) );
}
コード例 #17
0
int
main (int argc, char *argv[])
{
    int *sray, *rray;
    int *sdisp, *scounts, *rdisp, *rcounts;
    int ssize, rsize, i, k, j;
    float z;

    init_it (&argc, &argv);
    scounts = (int *) shmem_malloc (sizeof (int) * numnodes);
    rcounts = (int *) shmem_malloc (sizeof (int) * numnodes);
    sdisp = (int *) shmem_malloc (sizeof (int) * numnodes);
    rdisp = (int *) shmem_malloc (sizeof (int) * numnodes);
    /* 
       ! seed the random number generator with a ! different number on each
       processor */
    seed_random (myid);
    /* find data to send */
    for (i = 0; i < numnodes; i++) {
        random_number (&z);
        scounts[i] = (int) (10.0 * z) + 1;
    }
    printf ("-------myid= %d scounts=", myid);
    for (i = 0; i < numnodes; i++) {
        printf ("%d ", scounts[i]);
    }
    printf ("\n");

    /* send the data */
    // mpi_err = MPI_Alltoall(scounts,1,MPI_INT, rcounts,1,MPI_INT,
    // MPI_COMM_WORLD);
    shmem_barrier_all ();
    int other, j1;
    for (j1 = 0; j1 < numnodes; j1++) {
        shmem_int_put (&rcounts[myid], &scounts[j1], 1, j1);
    }
    shmem_barrier_all ();
    printf ("myid= %d rcounts=", myid);
    for (i = 0; i < numnodes; i++) {
        printf ("%d ", rcounts[i]);
    }
    printf ("\n");
    shmem_finalize ();
    return 0;
}
コード例 #18
0
ファイル: test_valarray.cpp プロジェクト: Arkshine/NS
void test_rope()
{
    TestValarray testValarray, testValarray2;
    size_t ropeSize = random_number(random_base);
	
    while ( testValarray.size() < ropeSize )
    {
        TestValarray::value_type x = random_number(random_base) ;	// initialize before use
        testValarray.push_back( x );
        testValarray2.push_back( TestValarray::value_type() );
    }
    WeakCheck( testValarray, test_insert_one<TestValarray>(testValarray) );
    WeakCheck( testValarray, test_insert_one<TestValarray>(testValarray, 0) );
    WeakCheck( testValarray, test_insert_one<TestValarray>(testValarray, testValarray.size()) );

    WeakCheck( testValarray, test_insert_n<TestValarray>(testValarray, random_number(random_base) ) );
    WeakCheck( testValarray, test_insert_n<TestValarray>(testValarray, random_number(random_base), 0 ) );
    WeakCheck( testValarray, test_insert_n<TestValarray>(testValarray, random_number(random_base), testValarray.size() ) );
	
    size_t insCnt = random_number(random_base);
    TestValarray::value_type *insFirst = new TestValarray::value_type[1+insCnt];

    WeakCheck( testValarray, insert_range_tester(testValarray, insFirst, insFirst+insCnt) );
    WeakCheck( testValarray, insert_range_at_begin_tester(testValarray, insFirst, insFirst+insCnt) );
    WeakCheck( testValarray, insert_range_at_end_tester(testValarray, insFirst, insFirst+insCnt) );

    ConstCheck( 0, test_construct_pointer_range<TestValarray>(insFirst, insFirst+insCnt) );
    delete[] insFirst;

    WeakCheck( testValarray, insert_range_tester(testValarray, testValarray2.begin(), testValarray2.end() ) );

    WeakCheck( testValarray, test_push_front<TestValarray>(testValarray) );
    WeakCheck( testValarray, test_push_back<TestValarray>(testValarray) );

    ConstCheck( 0, test_default_construct<TestValarray>() );
    ConstCheck( 0, test_construct_n<TestValarray>( random_number(random_base) ) );
    ConstCheck( 0, test_construct_n_instance<TestValarray>( random_number(random_base) ) );
    ConstCheck( 0, test_construct_iter_range<TestValarray>( testValarray2 ) );
    ConstCheck( testValarray, test_copy_construct<TestValarray>() );

    WeakCheck( testValarray, test_assign_op<TestValarray>( testValarray2 ) );
}
コード例 #19
0
int main(){
	for(int i = 0; i < COUNT; ++i){
		float result = random_number(0, MAX);

		int bin = (int)result;
		assert(bin >= 0);
		assert(bin < MAX);

		++bins[bin];
	}

	printf("# bin\tcount\n");

	for(int i = 0; i < MAX; ++i){
		printf("%i\t%u\n", i, bins[i]);
	}

	return 0;
}
コード例 #20
0
int main(int argc,char *argv[])
{
	int N=atoi(argv[1]),i;
	double average=0,standard_deviation=0;
	number_t x;

	srand((unsigned)time(NULL));
	for(i=1;i<=N;i++){
		x=random_number();
		average+=(double)x/N;
		standard_deviation+=(double)x*x/N;
	}
	standard_deviation=sqrt(standard_deviation-average*average);

	printf("average:%f\n",average);
	printf("standard_deviation:%f\n",standard_deviation);

	return(0);
}
コード例 #21
0
ファイル: game_manager.cpp プロジェクト: UAFCS600/skynet
void game_manager_t::create_game(const std::string& name)
{
	if(name.size()>max_name_size_m)
		throw std::runtime_error("Invalid game name \""+name+"\" (name cannot be greater than "+std::to_string(max_name_size_m)+").");
	if(name.size()==0||isspace(name[0])!=0||isspace(name[name.size()-1])!=0)
		throw std::runtime_error("Invalid game name \""+name+"\" (cannot start or end with whitespace).");
	if(games_m.count(name)>0)
		throw std::runtime_error("Game \""+name+"\" already exists.");

	uint64_t time=get_time();

	skynet::checkers::board_t starting_board("rrrrrrrrrrrr________bbbbbbbbbbbb");

	if(opening_moves_m.size()>0)
		starting_board=opening_moves_m[random_number(0,opening_moves_m.size())];

	skynet::checkers::game_info_t game{skynet::checkers::RED_TURN,{starting_board},time,time};
	games_m[name]=game;
}
コード例 #22
0
void test_list()
{
    TestList testList, testList2;
    size_t listSize = random_number(random_base);
  
    while ( testList.size() < listSize )
    {
        TestClass x;
        testList.push_back( x );
        testList2.push_back( TestClass() );
    }

    StrongCheck( testList, test_insert_one<TestList>(testList) );
    StrongCheck( testList, test_insert_one<TestList>(testList, 0) );
    StrongCheck( testList, test_insert_one<TestList>(testList, (int)testList.size()) );

    WeakCheck( testList, test_insert_n<TestList>(testList, random_number(random_base) ) );
    WeakCheck( testList, test_insert_n<TestList>(testList, random_number(random_base), 0 ) );
    WeakCheck( testList, test_insert_n<TestList>(testList, random_number(random_base), (int)testList.size() ) );
  
    size_t insCnt = random_number(random_base);
    TestClass *insFirst = new TestList::value_type[1+insCnt];

    WeakCheck( testList, insert_range_tester(testList, insFirst, insFirst+insCnt) );
    WeakCheck( testList, insert_range_at_begin_tester(testList, insFirst, insFirst+insCnt) );
    WeakCheck( testList, insert_range_at_end_tester(testList, insFirst, insFirst+insCnt) );

    ConstCheck( 0, test_construct_pointer_range<TestList>(insFirst, insFirst+insCnt) );
    delete[] insFirst;

    WeakCheck( testList, insert_range_tester(testList, testList2.begin(), testList2.end() ) );

    StrongCheck( testList, test_push_front<TestList>(testList) );
    StrongCheck( testList, test_push_back<TestList>(testList) );

    StrongCheck( testList, test_list_sort() );  // Simply to verify strength.
       
    ConstCheck( 0, test_default_construct<TestList>() );
    ConstCheck( 0, test_construct_n<TestList>( random_number(random_base) ) );
    ConstCheck( 0, test_construct_n_instance<TestList>( random_number(random_base) ) );
    ConstCheck( 0, test_construct_iter_range<TestList>( testList2 ) );
    ConstCheck( testList, test_copy_construct<TestList>() );

    WeakCheck( testList, test_assign_op<TestList>( testList2 ) );
}
コード例 #23
0
ファイル: game.c プロジェクト: hullerob/dices
void game_roll      (struct game *game) {
  int i;
  int occ[6] = {0, 0, 0, 0, 0, 0};
  int score;
  for (i = 0; i < game -> dices; i++) {
    occ[random_number()] ++;
  }
  score = get_score(occ);
  if (score == 0) {
    game -> cur_score = 0;
    game -> turns ++;
    game -> dices = 6;
  } else {
    game -> cur_score += score;
    game -> dices = get_dices (occ);
  }
  for (i = 0; i < 6; i++)
    game -> last_occ[i] = occ[i];
  update_dices (game);
}
コード例 #24
0
ファイル: c_ex07.c プロジェクト: arnabd88/CIVL-CS6110
int main(int argc,char *argv[]){
	int *sray,*rray;
	int *sdisp,*scounts,*rdisp,*rcounts;
	int ssize,rsize,i,k,j;
	float z;

	init_it(&argc,&argv);
	scounts=(int*)malloc(sizeof(int)*numnodes);
	rcounts=(int*)malloc(sizeof(int)*numnodes);
	sdisp=(int*)malloc(sizeof(int)*numnodes);
	rdisp=(int*)malloc(sizeof(int)*numnodes);
/*
! seed the random number generator with a
! different number on each processor
*/
	seed_random(myid);
/* find  data to send */
	for(i=0;i<numnodes;i++){
		random_number(&z);
		scounts[i]=(int)(10.0*z)+1;
	}
	printf("myid= %d scounts=",myid);
	for(i=0;i<numnodes;i++)
		printf("%d ",scounts[i]);
	printf("\n");
/* send the data */
	mpi_err = MPI_Alltoall(	scounts,1,MPI_INT,
						    rcounts,1,MPI_INT,
	                 	    MPI_COMM_WORLD);
	printf("myid= %d rcounts=",myid);
	for(i=0;i<numnodes;i++)
		printf("%d ",rcounts[i]);
	printf("\n");
#ifdef _CIVL
free(scounts);
free(rcounts);
free(sdisp);
free(rdisp);
#endif
    mpi_err = MPI_Finalize();
}
コード例 #25
0
ファイル: test_string.cpp プロジェクト: rickyharis39/nolf2
void test_string()
{
    TestString testString, testString2;
    EH_STD::size_t ropeSize = random_number(random_base);
	
    while ( testString.size() < ropeSize )
    {
        TestString::value_type x = TestString::value_type(random_number(random_base)) ;	// initialize before use
        testString.append(1, x );
        testString2.append(1, TestString::value_type() );
    }
    WeakCheck( testString, test_insert_one<TestString>(testString) );
    WeakCheck( testString, test_insert_one<TestString>(testString, 0) );
    WeakCheck( testString, test_insert_one<TestString>(testString, (int)testString.size()) );

    WeakCheck( testString, test_insert_n<TestString>(testString, random_number(random_base) ) );
    WeakCheck( testString, test_insert_n<TestString>(testString, random_number(random_base), 0 ) );
    WeakCheck( testString, test_insert_n<TestString>(testString, random_number(random_base), (int)testString.size() ) );
	
    EH_STD::size_t insCnt = random_number(random_base);
    TestString::value_type *insFirst = new TestString::value_type[1+insCnt];

    WeakCheck( testString, insert_range_tester(testString, insFirst, insFirst+insCnt) );
    WeakCheck( testString, insert_range_at_begin_tester(testString, insFirst, insFirst+insCnt) );
    WeakCheck( testString, insert_range_at_end_tester(testString, insFirst, insFirst+insCnt) );

    ConstCheck( 0, test_construct_pointer_range<TestString>(insFirst, insFirst+insCnt) );
    delete[] insFirst;

    WeakCheck( testString, insert_range_tester(testString, testString2.begin(), testString2.end() ) );
    /*
    WeakCheck( testString, test_push_front<TestString>(testString) );
    WeakCheck( testString, test_push_back<TestString>(testString) );
    */
    ConstCheck( 0, test_default_construct<TestString>() );
    // requires _Reserve_t    ConstCheck( 0, test_construct_n<TestString>( random_number(random_base) ) );
    ConstCheck( 0, test_construct_n_instance<TestString>( random_number(random_base) ) );
    ConstCheck( 0, test_construct_iter_range<TestString>( testString2 ) );
    ConstCheck( testString, test_copy_construct<TestString>() );

    WeakCheck( testString, test_assign_op<TestString>( testString2 ) );
}
コード例 #26
0
void write_read()
{
	int i, j, count = 0;
	char ch[ArrayLen];
	FILE *fp;
	char *q;

	fp = fopen("Read.txt","rt");
	if(fp == NULL){
		puts("cannot open file");
		exit(0);
	}

	q = (char *) malloc (sizeof(char) * 1000);

	while(!feof(fp))
	{
		ch[count] = fgetc(fp);
		count++;
	}

	printf("%d\n", count - 1);

	for(i = 0; i < 1000000; i++)
	{
		for(j = 0; j < count - 1; j++)
		{
			q[j] = ch[random_number(1, count - 1)];
			//printf("%c", q[j]);
		}

		//printf("\n");		
	}

	free(q);

	fclose(fp);

}
コード例 #27
0
ファイル: crypt.c プロジェクト: braddr/cold
/*
// Encrypt a string.  The salt can be NULL--force SHS encryption,
// match_crypted() will handle older DES passwords
*/
cStr * strcrypt(cStr * key, cStr * salt) {
    char   pwd_buf[SHS_OUTPUT_SIZE];  /* output buffer for the password */
    uChar * pp, * sp, rsalt[9];         /* 8 chars of salt, one NULL */
    Int    x,
           pl,
           sl;

    if (!salt) {
        random_salt:

        for (x=0; x < 8; x++)
            rsalt[x] = ascii64[random_number(64)];
        rsalt[8] = 0;
        sp = rsalt;
        sl = 8;
    } else {
        sp = (uChar *) string_chars(salt);
        if (sp[0] == '$' && sp[1] == '2' && sp[2] == '$') {
            sp += 3;
            for (x=0; x < 8 && sp[x] != '$'; x++)
                rsalt[x] = sp[x];
            rsalt[x] = 0;
            sp = rsalt;
            sl = strlen((char *) sp);
            if (!sl)
                goto random_salt;
        } else {
            sl = string_length(salt);
        }
    }

    pp = (uChar *) string_chars(key);
    pl = string_length(key);

    shs_crypt(pp, pl, sp, sl, pwd_buf);

    return string_from_chars(pwd_buf, strlen(pwd_buf));
}   
コード例 #28
0
ファイル: main.c プロジェクト: young-k/Notes
int main() {
  printf("[PARENT] Process Prior to forking\n");
  pid_t a,b,status;
  a = fork();
  if (a != 0) {
    b = fork();
    if (b != 0) {
      int pid = wait(&status);
      printf("[PARENT] Time waited by child: %d\n", WEXITSTATUS(status));
      printf("[PARENT] PID of completed child: %d\n", pid);
      printf("[PARENT] Program concluded\n");
    }
  }
  
  if (a == 0 || b == 0) {
    printf("[CHILD] PID: %d\n", getpid());
    int r = random_number();
    sleep(r);
    return r;
  }
  
  return 0;
}
コード例 #29
0
ファイル: random.hpp プロジェクト: devinamatthews/tblis
int random_weighted_choice(const Weights& w)
{
    using T = typename Weights::value_type;

    auto n = w.size();
    TBLIS_ASSERT(n > 0);

    T s = 0;
    for (unsigned i = 0;i < n;i++)
    {
        TBLIS_ASSERT(w[i] >= 0);
        s += w[i];
    }

    T c = random_number(s);
    for (unsigned i = 0;i < n;i++)
    {
        if (c < w[i]) return i;
        c -= w[i];
    }

    return n-1;
}
コード例 #30
0
ファイル: unittest.c プロジェクト: cr8zd/cs362w16
/**
 * Function: updatePile
 * Inputs: player, count of elements to update, pile type to update, struct gameState
 * Outputs: None
 * Description:  updates a pile of cards to the number of elements requested in count
 */
int updatePile(int player, int count, int pile, struct gameState *state){

	int i;
	int *ptr;
	int oldCount;

	if(pile == HAND)
	{
		oldCount = state->handCount[player];
		state->handCount[player] = count;
		ptr = state->hand[player];
	}
	else if(pile == DECK)
	{
		oldCount = state->deckCount[player];
		state->deckCount[player] = count;
		ptr = state->deck[player];
	}
	else if(pile == DISCARD)
	{
		oldCount = state->discardCount[player];
		state->discardCount[player] = count;
		ptr = state->discard[player];
	}

	for(i = 0; i < count; i++){
		ptr[i] = random_number(0, treasure_map);
	}

	//clear values higher than count
	for(i = count; i < oldCount; i++){
		ptr[i] = 0;
	}

	return 0;
}