示例#1
0
	Trigger::Trigger(  irr::scene::ISceneManager *smgr ) : triggered( false ), promptShown( false )
	{
		irr::video::ITexture* tex;

		this->smgr = smgr;
		GUIEnv = smgr->getGUIEnvironment();

		// get a random number for which popup to show:
		boost::mt19937 rng;
		unsigned int seed = static_cast<unsigned int>(std::time(0));
		rng.seed(seed);
		boost::uniform_int<>five(1, 5);
		boost::variate_generator<boost::mt19937&, boost::uniform_int<> > getrand(rng, five);
		int i = getrand();

		// get texture:
		std::string textureName = "PopUp";
		textureName.append(boost::lexical_cast<std::string>(i));
		textureName.append(".png");
		tex = smgr->getVideoDriver()->getTexture(textureName.c_str());
		
		// create the image:
		img = GUIEnv->addImage(irr::core::rect<irr::s32>(-2, -2, 1, 1) );
		img->setUseAlphaChannel(true);
		img->setImage(tex);
		img->setScaleImage( true );
		smgr->getVideoDriver()->removeTexture(tex);
	}
示例#2
0
文件: main.c 项目: DSG888/SibSUTIS
double lin()
{
	unsigned int seed = omp_get_thread_num(); 
	uint64_t in = 0;
	double s = 0;
	double t = omp_get_wtime();
	
	for (uint64_t i = 0; i < n; ++i)
	{
		double x = getrand(&seed) * PI;
		double y = getrand(&seed);
		if (y <= sin(x))
		{
			++in;
			s += func(x, y);
		}
	}
	double v = PI * in / n;
	double res = v * s / in;
	
	t = omp_get_wtime() - t;
	printf("Result: %.12f, n %d\n", res, n);
	printf("Elapsed time (sec.): %.12f\n", t);
	return t;
}
示例#3
0
文件: main.c 项目: DSG888/SibSUTIS
double par()
{
	uint64_t in = 0;
	double s = 0;
	double t = omp_get_wtime();
	#pragma omp parallel
	{
		double s_loc = 0;
		uint64_t in_loc = 0;
		unsigned int seed = omp_get_thread_num(); 
		#pragma omp for nowait
		for (uint64_t i = 0; i < n; ++i)
		{
			double x = getrand(&seed) * PI;
			double y = getrand(&seed);
			if (y <= sin(x))
			{
				++in_loc;
				s_loc += func(x, y);
			}
		}
		#pragma omp atomic
		s += s_loc;
		#pragma omp atomic
		in += in_loc;
	}
	double v = PI * in / n;
	double res = v * s / in;
	t = omp_get_wtime() - t;
	printf("Result: %.12f, n %d\n", res, n);
	printf("Elapsed time (sec.): %.12f\n", t);
	return t;
}
示例#4
0
int _start(void) {
    crash_handler_word[0] = crash_handler;
    int max = 1000;
    cursor_pos = INITIAL_CURSOR_POS;
    clear_screen_with_border(BACKGROUND, FOREGROUND, border_size);
    banner();
    uint32_t number = (getrand()%max)+1;
    int remaining = 1337;

    while(1) {
        char buffer[32] = {0};
        char *episode_name = NULL;
        int season = getrand()%7;;
        int episode_number;
        if(season == 0) {
            episode_number = getrand()%12;
        }
        else {
            episode_number = getrand()%22;
        }
        episode_name = episodes[season][episode_number];
        episode_number++;
        season++;
        //format the question
        question[29] = (episode_number >= 10) ? ('0' + (episode_number/10)) : ' ';
        question[30] = '0' + (episode_number%10);
        question[42] = '0' + season;

        //ask the question
        process_string(question);

        process_text(buffer);
        if(0 == strcasecmp(buffer,episode_name)) {
            if(remaining == 0) {
                print_secret();
                break;
            }
            else {
                process_string("Correct! get ");
                print_number(remaining--);
                process_string(" more correct to learn the password\r\r");
            }
        }
        else {
            process_string("Wrong! The answer is \"");
            process_string(episode_name);
            process_string("\"\r\r");
        }
    }
    //infinite loop
    while(1) {
        wait_for_interrupt();
    }
}
示例#5
0
void RollPlayer(Player *ThisPlayer)
{
	short ModHealth = 0;
	short ModStrength = 0;
	short ModDex = 0;
	short ModInt = 0;
	//printw("Rolling Mods\n");
	//refresh();
	ModHealth = getrand(ThisPlayer->PClass.ModHealthMinMax.X, ThisPlayer->PClass.ModHealthMinMax.Y);
	//printw("Mod Health Complete %d\n", ModHealth);
	//refresh();
	ModStrength = getrand(ThisPlayer->PClass.ModStrMinMax.X, ThisPlayer->PClass.ModStrMinMax.Y);
	//printw("Mod Strength Complete %d\n", ModStrength);
	//refresh();
	ModDex = getrand(ThisPlayer->PClass.ModDexMinMax.X, ThisPlayer->PClass.ModDexMinMax.Y);
	//printw("Mod Dex Complete %d\n", ModDex);
	//refresh();
	ModInt = getrand(ThisPlayer->PClass.ModIntMinMax.X, ThisPlayer->PClass.ModIntMinMax.Y);
	//printw("Mod Int Complete %d\n", ModInt);
	//refresh();
	ThisPlayer->Strength = getrand(ThisPlayer->PRace.StrMinMax.X + ModStrength, ThisPlayer->PRace.StrMinMax.Y + ModStrength);
	ThisPlayer->Health = getrand(ThisPlayer->PRace.HealthMinMax.X + ModHealth, ThisPlayer->PRace.HealthMinMax.Y + ModHealth);
	ThisPlayer->Dex = getrand(ThisPlayer->PRace.DexMinMax.X + ModDex, ThisPlayer->PRace.DexMinMax.Y + ModDex);
	ThisPlayer->Int = getrand(ThisPlayer->PRace.IntMinMax.X + ModInt, ThisPlayer->PRace.IntMinMax.Y + ModInt);
	//printw("Character Rolled\n");
	ThisPlayer->CurrHealth = ThisPlayer->Health;
}
示例#6
0
文件: xnufuzz.c 项目: Berrrry/xnufuzz
unsigned long getarg(void) {
    int state = rand() % 5;
    static char b[128];

    switch(state) {
    /* userland addr */
    case 0:
        return 0x0804fd00;
        break;
    /* unmapped addr */
    case 1:
        return 0x0000a000;
        break;
    /* kernel addr, this is a guess ... should actually get a real one ...  */
    case 2:
        return 0xc01fa0b6;
        break;
    /* some number */
    case 3:
        return getnumber();
        break;
    case 4:
        getrand(b);
        return &b;
        break;
    }
}
示例#7
0
文件: main.cpp 项目: shubh24/MfoPaper
int main()
{
    srand(time(NULL));
    data dat;
    readfile(dat, "../../data/ks_19_0");
    int items = dat[0].value;
    population *pop, popalpha;
    initialize_population(popalpha, items);
    pop = &popalpha;
    //print(*pop);

    bat best = get_best(*pop);

    int iterations = 200;
    while(iterations > 0){
        new_solutions(*pop,dat);
        calc_fitness(*pop, dat);
        if(getrand()> 0.5){
            best = get_best(*pop);
            move_bat(best, rand()%5, dat); // amplitude is 2
        }

        if(fitness(best, dat) > fitness((*pop).best, dat))
            (*pop).best = best;

        iterations--;
    }
    print(*pop);
}
示例#8
0
文件: 2828.cpp 项目: scPointer/OI
void insert(Node* &o,int pos,int v)
{
	if(o==null)
	{
		o=newNode();
		o->son[0]=o->son[1]=null;
		o->w=getrand();
		o->val=v;
		o->sz=1;
	}
	else
	{
		int d= o->son[0]->sz;
		if(pos<=d)
		{
			insert(o->son[0],pos,v);
			o->maintain();
//			if(now%7==0)
				if(o->son[0]->w > o->w) rotate(o,1);
		}
		else
		{
			insert(o->son[1],pos-d-1,v);
			o->maintain();
//			if(now%7==0)
				if(o->son[1]->w > o->w) rotate(o,0);
		}
	}
}
示例#9
0
文件: tester.c 项目: DSG888/SibSUTIS
int *getrandmas(int size)
{
	int *tmpmas = malloc(sizeof(int) * size);
	int *mas = malloc(sizeof(int) * size);
	//TODO Проверка
	int i, r, s = 0;;
	for (i = size; 0 < i; --i)
	{
		tmpmas[i - 1] = i;
	}
	for (i = 0; size > i; ++i)
	{
		while(1)
		{
			if ((i) && ( (i-s) >= (size-i) ))
		//	if ((i) && ( (i-s) >= size/2.1 ))//i->0
			{
				QuickSort(tmpmas, s, size - 1);
				s = i;
			}
			r = getrand(s, size);
			if (tmpmas[r])
			{
				mas[i] = tmpmas[r];
				tmpmas[r] = 0;
				break;
			}
		}
	}
	free(tmpmas);
	return mas;
}
示例#10
0
文件: main.c 项目: simplex1337/saod
int main()
{
    FILE *data = fopen("base.txt", "r");
    int i, n;
    for (i = 0; i < 200000; i++)
        fscanf(data, "%s\n", word[i]);
    fclose(data);
    struct bstree *tree;
    tree = bstree_create(word[0], 0);  
    for (i = 2; i <= 200000; i++) {
        bstree_add(tree, word[i - 1], i - 1);
        if (i % 10000 == 0)
            for (n = 0; n < 100; n++) {
                sleep(1);
                char *w = word[getrand(0, i - 1)];
                printf("%s\n", w);
                double t = wtime();
                struct bstree *node = bstree_lookup(tree, w);
                t = wtime() - t;
                printf("%s\n", node->key);
                printf("n = %d; time = %.6f\n", i, t);
                FILE *log = fopen("bstree_1.log", "a");
                fprintf(log, "%d\t%.6f\n", i, t);
                fclose(log);
            }
    }
    return 0;
}
void generateRandomVector(u32 n, vectoru32 &v) {
  v.resize(n);
  for ( u32 &val : v)
    //val = rnd();
    val = getrand(1, 1001); //[a, b[
  //val = distribution(generator);
}
示例#12
0
main ()
{
	register long	a, n, k;
	long	getrand ();

	setrand (314159269, 453806245, 13);

	a = 1234;
	n = 0;
	k = 0;

	for (;;)
	{
#define	PRINT_NOs
#ifdef	PRINT_NOs
		printf ("n = %P, %u\n", a, a);
#endif	PRINT_NOs

		n++;
		k++;

		if ((a = getrand (a)) == 1234)
			break;

		if (k == 1000000)
		{
			k = 0;
			printf("passaram-se %d numeros sem repetição \n", n);
		}

	}
	printf ("deu igual depois de %d numeros \n", n);
}
示例#13
0
int main()
{
	uint r;
	std::srand( std::time(NULL) );

	r = getrand();  printf("%08x\n", r);
	r = getrand();  printf("%08x\n", r);
	r = getrand();  printf("%08x\n", r);
	r = getrand();  printf("%08x\n", r);
	r = getrand();  printf("%08x\n", r);
	r = getrand();  printf("%08x\n", r);
	r = getrand();  printf("%08x\n", r);
	r = getrand();  printf("%08x\n", r);
	r = getrand();  printf("%08x\n", r);
	r = getrand();  printf("%08x\n", r);

	return 0;
}
示例#14
0
文件: demography.cpp 项目: jokoon/eio
//void demography  :: add()
//{
////    if(false)
//    {
//        b2CircleShape Shape;
//        Shape.m_radius = radius;
//        auto position =
//            Vec2(wsize.x*getrangerand(.1,.9),
//                 wsize.y*getrangerand(.1,.9));
//
//        auto Body = makebody(World,&Shape,conv(position),b2_dynamicBody,0,0.01,0,.9);
//
//        Body->SetLinearVelocity(
//        b2Vec2(5*getrangerand(-1,1),
//            5*getrangerand(-1,1)));
//        cellbodies.push_back(Body);
//        pos.push_back(b2Vec2());
//        
////        cells.push_back(CircleShape(0,4));
////        cells.back().setFillColor(Color(255,80,160));
////        cells.back().setRadius(SCALE*radius*GR_PH_COEFF);
////        cells.back().setOrigin(cells.back().getRadius(), cells.back().getRadius());
//        vbunk.add();
//    //    cells.back().setPosition(conv(position));
//    }
//    if(false)
//    {
//        pos.push_back(b2Vec2());
//    //    pos_sf.push_back(Vec2());
//        
//        b2BodyDef BodyDef;
//        BodyDef.position = b2Vec2
//        ((getrand(0.3)+0.2)*wsize.x/SCALE,
//         (getrand(0.3)+0.2)*wsize.y/SCALE);
//        BodyDef.type = b2_dynamicBody;
//    //    BodyDef.linearDamping=dampen;
//        b2Body* Body = World.CreateBody(&BodyDef);
//        
//        b2CircleShape Shape;
//        Shape.m_radius = radius;
//        //Body->setv
//        b2FixtureDef FixtureDef;
//        FixtureDef.density = 4.f;
//        FixtureDef.restitution = .9f;
//        FixtureDef.shape = &Shape;
//        Body->CreateFixture(&FixtureDef);
//        Body->SetLinearVelocity(b2Vec2
//            (5*getrangerand(-1,1),
//             5*getrangerand(-1,1)));
//        cellbodies.push_back(Body);
//        
//        cells.push_back(CircleShape(SCALE,4));
//        cells.back().setFillColor(Color(255,80,160));
//        cells.back().setRadius(SCALE*radius);
//        cells.back().setOrigin(cells.back().getRadius(), cells.back().getRadius());
//    }
//    lb2(cells.size());
//}
void demography  :: add_agent(Vec2 position, int is_enemy)

{
    b2CircleShape shape,shape_s,shape_s_e;
    shape       .m_radius = radius;
    shape_s     .m_radius = sensor_radius;
    shape_s_e   .m_radius = sensor_radius_e;

    auto Body = make_body(World,conv(position),b2_dynamicBody,dampen);
    b2FixtureDef fixdef, fixdef_s, fixdef_s_e;
    if(use_masks)
    {
        fixdef      = make_fixture(static_cast<b2Shape*>(&shape),    false, &filters[is_enemy][0],.1,4);
        //fixdef_s    = make_fixture(static_cast<b2Shape*>(&shape_s),  true,  &filters[is_enemy][1]    );
        //fixdef_s_e  = make_fixture(static_cast<b2Shape*>(&shape_s_e),true,  &filters[is_enemy][2]);
    }
    else
    {
        fixdef = make_fixture  (static_cast<b2Shape*>(&shape),false);
        fixdef.density=4;
        //fixdef_s = make_fixture(static_cast<b2Shape*>(&shape_s),true);
        //fixdef_s_e = make_fixture(static_cast<b2Shape*>(&shape_s_e),true);
    }
    Body->CreateFixture(&fixdef);
    //Body->CreateFixture(&fixdef_s);
    //Body->CreateFixture(&fixdef_s_e);
    if(!is_enemy)cellbodies.insert(Body);
    //if(draw_sensors)
    //{
    //    sensors[Body]=(CircleShape(SCALE*shape_s.m_radius,16));
    //    sensors[Body].setFillColor(Color(0,0,0,0));
    //    sensors[Body].setOutlineColor(Color(64,64,64));
    //    //sensors[Body].setOutlineColor(Color(0,64,0));
    //    sensors[Body].setOutlineThickness(0.5);
    //    sensors[Body].setOrigin(sensors[Body].getRadius(), sensors[Body].getRadius());

    //    sensors2[Body]=(CircleShape(SCALE*shape_s_e.m_radius,16));
    //    sensors2[Body].setFillColor(Color(0,0,0,0));
    //    //sensors2[Body].setOutlineColor(Color(96,0,0));
    //    sensors2[Body].setOutlineColor(Color(64,64,64));
    //    sensors2[Body].setOutlineThickness(0.5);
    //    sensors2[Body].setOrigin(sensors2[Body].getRadius(), sensors2[Body].getRadius());
    //}
#define USE_SHAPES
#ifdef USE_SHAPES
    cells[Body]=CircleShape(SCALE,getrangerand(3,6));
    cells[Body].setFillColor(rgb_from_hue(getrand(1)));
    cells[Body].setRadius(SCALE*radius);
    cells[Body].setOrigin(cells[Body].getRadius(), cells[Body].getRadius());
#else
    vbunk.add();
#endif
    nears[Body]=unordered_set<b2Body*>();
    pos.push_back(b2Vec2());
}
示例#15
0
void new_solutions(population &pop, data dat)
{
    int items = pop.items;

    for(int i = 0; i < items; i++)
    {
        pop.freq[i] = freq_min + (freq_max - freq_min)*getrand();
        pop.velocity[i] = (int)distance(pop.bats[i], pop.bats[0], items)*pop.freq[i];
        move_bat(pop.bats[i], pop.velocity[i], dat);
        pop.rate[i] = 0.5;
    }
}
示例#16
0
int main(int argc, char **argv)
{
  char line[256];
  char buf[1024];
  char *mem;
  int length;
  int fd;
  char *path;

  if(fgets(line, sizeof(line), stdin) == NULL) {
      errx(1, "reading from stdin");
  }

  if(strncmp(line, CL, strlen(CL)) != 0) {
      errx(1, "invalid header");
  }

  length = atoi(line + strlen(CL));

  if(length < sizeof(buf)) {
      if(fread(buf, length, 1, stdin) != length) {
          err(1, "fread length");
      }
      process(buf, length);
  } else {
      int blue = length;
      int pink;

      fd = getrand(&path);

      while(blue > 0) {
          printf("blue = %d, length = %d, ", blue, length);

          pink = fread(buf, 1, sizeof(buf), stdin);
          printf("pink = %d\n", pink);

          if(pink <= 0) {
              err(1, "fread fail(blue = %d, length = %d)", blue, length);
          }
          write(fd, buf, pink);

          blue -= pink;
      }

      mem = mmap(NULL, length, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
      if(mem == MAP_FAILED) {
          err(1, "mmap");
      }
      process(mem, length);
  }

}
u32 randomizedPartition(vectoru32& v, u32 p, u32 r){
  //srand(wtime());
  u32 i = getrand(p, r + 1);
  //srand(wtime());
  //u32 j = getrand(p, r + 1);
  //srand(wtime());
  //u32 k = getrand(p, r + 1);
  //u32 median = (i + j + k)/3;
  u32 tmp = v[i];
  v[i] = v[r];
  v[r] = tmp;
  return partition(v, p, r);
}
示例#18
0
void throwDices() {
    printf("Es wird gewuerfelt...\n");

    for (int i = 0; i < 5; i++) {
        if (dicesHolder[i] == false) {
            dices[i] = getrand();
        }
    }

    showAllDices();
    //resetDicesHolder();
    pause();
    showAllCombinations();
}
示例#19
0
int DoHTML(s_info * info, int form_method, char **getvars, char **postvars)
{

	htmlHeaderExpires("Lidar Web Page");
	htmlBody();

	switch (info->run) {
	case ACQUIRE:
	case REPLOT:
		printf
		    ("\n<img border=\"0\" src=\"/img%s.png?id=%d\" align=\"left\">\n",
		     info->pREMOTE_ADDR, getrand(6));
		break;

	case STOP_SERVER:
		printf
		    ("<b><font face=\"Arial Black\"> STOP Server Request from: %s</b><br><br> %s</font><br><br>\n",
		     getenv("REMOTE_ADDR"), getenv("HTTP_USER_AGENT"));

		break;
	case START_SERVER:

		printf
		    ("<b><font face=\"Arial Black\"> Request from %s:</b><br><br> %s</font><br><br>\n",
		     getenv("REMOTE_ADDR"), getenv("HTTP_USER_AGENT"));

		printf
		    ("<b><font face=\"Arial Black\"> %s now streaming to:</b><br><br> IP-ADDR:  %s <br>ADC Port# %s <br>DAC Port# %s <br>CTL Port# %s </font>\n",
		     "fpga_netd", info->pREMOTE_ADDR,
		     postvars[info->server.adc_port],
		     postvars[info->server.dac_port],
		     postvars[info->server.ctl_port]);

		break;

	case MULTIMETER:
		break;
	case SHOWSAMPLES:
		break;
	case GNUPLOT_FILES:
		DoFiles(info);
		break;
	default:

		break;
	}
	htmlFooter();
	fflush(stdout);
	return 0;
}
示例#20
0
int _start(void) {
    crash_handler_word[0] = crash_handler;
    int max = 1000;
    cursor_pos = INITIAL_CURSOR_POS;
    clear_screen_with_border(BACKGROUND, FOREGROUND, border_size);
    banner();
    uint32_t number = (getrand()%max)+1;
    int remaining = 10;
    while(1) {
        char buffer[64] = {0};
        process_text(buffer,remaining);
        if(remaining <= 0) {
            number = (getrand()%max)+1;
            remaining = 10;
        }
        int guess = atoi(buffer);
        if(guess <= 0 || guess > max) {
            process_string("That is not a valid guess\r");
        }
        else if(guess == number) {
            process_string("Correct! The first word to the passphrase is \"sulphuric\"\r");
            process_string("Please reset now\r");
            break;
        }
        else if(guess < number) {
            process_string("Your guess is too low\r");
        }
        else {
            process_string("Your guess is too high\r");
        }
        remaining -= 1;
    }
    //infinite loop
    while(1) {
        wait_for_interrupt();
    }
}
示例#21
0
int
main(int argc, char * argv[])
{
	if (argc != 3)
		usage(argv[0]);

	int n = atol(argv[2]);
	srand(701888);

	env = sp_env();
	sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, "./sophia_bench_data");
	db = sp_open(env);
	if (db == NULL) {
		printf("open: %s\n", sp_error(env));
		return 1;
	}
	
	int rc = 0;
	unsigned long long start = now();
	
	switch (benchof(argv[1]))
	{
	case SETSEQ: rc = setseq(n);
		break;
	case SETRAND: rc = setrand(n);
		break;
	case GETSEQ:rc = getseq(n);
		break;
	case GETRAND: rc = getrand(n);
		break;
	case RANGEFWD: rc = rangefwd(n);
		break;
	case UNKNOWN:
		printf("unknown operation\n");
	}

	if (rc == 0) {
		unsigned long long diff = now() - start;
		float rps = n / (diff / 1000.0);
		printf("%d rps\n", (int)rps);
	}
	if (keytraversed > 0 && keytraversed != n)
		printf("(%d keys traversed)\n", keytraversed);

	sp_destroy(db);
	sp_destroy(env);
	return rc;
}
示例#22
0
void capture(int form_method, char **getvars, char **postvars)
{

	htmlHeaderNocache("AWG Demo	Web	Page");
	htmlBody();

		printf("\n<img border=\"0\"	src=\"/img.png?id=%s\" align=\"left\">\n",itostr	(getrand(6)	,6,1,1));

	htmlFooter();
	fflush(stdout);
	cleanUp(form_method, getvars, postvars);

	display_on_framebuffer();

  return;
}
示例#23
0
文件: main.c 项目: evg-kazartseff/DSA
int main(int argc, char *argv[])
{
    if (argc < 2) {
        printf("Missing size of array!\n");
        return EXIT_FAILURE;
    }

    int size_array = atoi(argv[1]);
    int *array = (int *) malloc(size_array * sizeof(uint32_t));

    for (int i = 0; i < size_array; i++) {
        array[i] = getrand(0, 100000);
//      printf ("array[%d]= %d ",i,array[i]);
    }

    double time = wtime();

    for (int i = 0; i < size_array - 1; i++) {
        for (int j = 0; j < size_array - i - 1; j++) {
            if (array[j] > array[j + 1]) {
                int tmp = array[j];
                array[j] = array[j + 1];
                array[j + 1] = tmp;
            }
        }
    }

/*    for (int i = 0; i < size_array; i++) {
      printf ("array[%d]= %d ",i,array[i]);
    }*/

    time = wtime() - time;

    FILE *tb;
    tb = fopen("bubblesort.dat", "a");
    fprintf(tb, "%d %.6f\n", size_array, time);

    free(array);
    return EXIT_SUCCESS;
}
示例#24
0
void DoFiles(s_info * info)
{
	int rand = getrand(6);
	printf("<hr>\n<menu>\n");

	info->pFile_samples = fopen(info->pFILENAME_T_OUT, "r");
	if (info->pFile_samples) {
		fclose(info->pFile_samples);
		printf
		    ("  <li><font face=\"Arial Black\"><a href=\"t_samples.txt_%s?id=%d\">Time Samples</a></font></li>\n",
		     info->pREMOTE_ADDR, rand);
	}

	info->pFile_init = fopen(info->pFILENAME_GNUPLT, "r");
	if (info->pFile_init) {
		fclose(info->pFile_init);
		printf
		    ("  <li><font face=\"Arial Black\"><a href=\"gnu.plt_%s?id=%d\">Gnuplot File</a></font></li>\n",
		     info->pREMOTE_ADDR, rand);
	}

	info->pFile_rawsamples = fopen(info->pFILENAME_RAW_OUT, "r");
	if (info->pFile_rawsamples) {
		fclose(info->pFile_rawsamples);
		printf
		    ("<li><font face=\"Arial Black\"><a href=\"raw_samples.txt_%s?id=%d\">Raw Samples</a></font></li>\n",
		     info->pREMOTE_ADDR, rand);
	}

	if ((info->pFile_rawsamples == NULL) && (info->pFile_samples == NULL)
	    && (info->pFile_init == NULL))
		printf
		    ("  <li><font face=\"Arial Black\">No Files available from %s</font></li>\n",
		     info->pREMOTE_ADDR);

	printf("</menu>\n<hr>\n");

	return;
};
void Character::aiAttackFormationSin(Character *c, Arduboy *d, const unsigned char s[], bool *boolGS) {
  wep.countFrames++;
  Rect mainC = {c->y, c->x, c->h, c->w};
  Rect bel = {c->wep.y, c->wep.x, 1, 1};
  Rect ai = {x, y, h, w};

  if (randState) {
    randO = getrand(MIN, MAX);
    randState = 0;
  }

  if (lifeState) {
    d->drawBitmap(x, y, s , w, h, WHITE);

    if (d->everyXFrames(2)) {
      if (sinX <= 3.1) {
        sinX += 0.05;
        sinY = sin(sinX);
        x =  (int)(sinX * 41);
        y =  (int)(sinY * randO);
      }
    }
  }
  if (phy.collide(ai, bel)) {
    lifeState = 0;
    y = 166;
    c->killCount = c->killCount + 1;
  }
  if (phy.collide(ai, mainC)) {
    *boolGS = 0;
  }
  if (wep.countFrames > 250) {
    wep.countFrames = 0;
    sinX = 0;
    randState = 1;
    lifeState = 1;
  }
}
示例#26
0
// return a random number between min and max inclusive
int random(int min, int max)
{
   int range, val;

   if (max < min)
   {
      NX_ERR("random(): warning: max < min [%d, %d]\n", min, max);
      min ^= max;
      max ^= min;
      min ^= max;
   }

   range = (max - min);

   if (range >= RAND_MAX)
   {
      NX_ERR("random(): range > RAND_MAX\n", min, max);
      return 0;
   }

   val = getrand() % (range + 1);
   return val + min;
}
示例#27
0
文件: fire.c 项目: sherry97/parallel
int main()
{
	double probability, p, dp, starttime, endtime;
	int x, y, size, steps, trials, t, totalsteps;
	bool noneburnt;
	size = forestsize;
	char forest[size][size], newforest[size][size];

        // init forest
	dp = 0.02;
	trials = 100;
	starttime = gettime();
	for (probability = 0; probability < 1+dp/10; probability+=dp)
	{
		totalsteps = 0;
		for (t = 0; t < trials; t++)
		{
			for (x = 0; x < size; x++)
			{
				for (y = 0; y < size; y++)
				{
					p = getrand();
					if (p <= probability) forest[x][y] = '^';
					else forest[x][y] = '-';
					newforest[x][y] = forest[x][y];
				}
			}

		        // burn first column
		        for (x = 0; x < size; x++)
		        {
				if (forest[x][0] != '^') continue;
				forest[x][0] = '*';
				newforest[x][0] = '*';
		        }
			// display(0, size, forest);
		
			// burn forest
			steps = 0;
			while (1)
			{
				noneburnt = true;
				for (x = 0; x < size; x++)
				{
					for (y = 0; y < size; y++)
					{
						if (forest[x][y] != '*') continue;
						forest[x][y] = '-';
					        if (x-1 >= 0 && forest[x-1][y] == '^')
					        {
					         	newforest[x-1][y] = '*';
							noneburnt = false;
					        }
					        if (x+1 < size && forest[x+1][y] == '^')
					        {
					         	newforest[x+1][y] = '*';
							noneburnt = false;
					        }
					        if (y-1 >= 0 && forest[x][y-1] == '^')
					        {
					        	newforest[x][y-1] = '*';
							noneburnt = false;
					        }
					        if (y+1 < size && forest[x][y+1] == '^')
					        {
					        	newforest[x][y+1] = '*';
							noneburnt = false;
					        }
					}
				}
				update(size, forest, newforest);
				steps++;
				// display(++steps, size, forest);
				if (noneburnt) break;
			}
			totalsteps+=steps;
		}
		// printf("%f %f\n", probability, (double)totalsteps/(double)trials/(double)size);
	}
	endtime = gettime();
	printf("run time: %0.16f seconds\n" , endtime-starttime ) ;
	return 0;
}
示例#28
0
void generateRandomVector(u32 n, vectoru32 &v) {
  v.resize(n);
  for ( u32 &val : v)
    //val = rnd();
    val = getrand(0, 1001); // [a, b[ = [a , b - 1]
}
示例#29
0
文件: random2.cpp 项目: mohitsh/cpp
int main()
{
	std::cout << getrand(1,6) << std::endl;
}
示例#30
0
/*
 * Get a number more random than what getrand() gives.
 */
static unsigned
getrnum(void)
{
	return((getrand())>>(getrand()%17));
}