当前位置: 首页>>代码示例>>C++>>正文


C++ randomize函数代码示例

本文整理汇总了C++中randomize函数的典型用法代码示例。如果您正苦于以下问题:C++ randomize函数的具体用法?C++ randomize怎么用?C++ randomize使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了randomize函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main( void )
{
 dword FarFreeMemoryAtStart=(unsigned long)farcoreleft();

 printf("\n\n                        Reliable file system"
          "\n                                  by"
          "\n                                Dvorka"
          "\n"
          "\n                 Compiled at %s, %s\n", __DATE__, __TIME__
       );
 printf(  "                  Starting with far heap: %luB \n", FarFreeMemoryAtStart );

 randomize();







  InitializeSimulation( INIT_WRITE_TABLE, INIT_CREATE_DEVICES );   // create everything new

  FSCreatMasterBoot( 0x80, 512, 1 );
  FSCreatMasterBoot( 0x81, 512, 1 );
  FSCreatMasterBoot( 0x82, 512, 1 );

  // data stripe
  FSCreatPartition( 0x80, 1, 0, 500, ACTIVE_PARTITION );
  // parity stripe
  FSCreatPartition( 0x80, 2, 501, 1023, NONACTIVE_PARTITION );
  // data stripe
  FSCreatPartition( 0x81, 1, 0, 500, NONACTIVE_PARTITION );
  // swap party
  FSCreatPartition( 0x81, 2, 501, 1023, NONACTIVE_PARTITION );
  // data stripe
  FSCreatPartition( 0x82, 1, 0, 500, NONACTIVE_PARTITION );
  // data stripe
  FSCreatPartition( 0x82, 2, 501, 1001, NONACTIVE_PARTITION );

  // format parties
  FSFormat( 0x80, 1, RFS_DATA );
  FSFormat( 0x80, 2, RFS_DATA  );
  FSFormat( 0x81, 1, RFS_DATA );
  FSFormat( 0x81, 2, RFS_SWAP );
  FSFormat( 0x82, 1, RFS_DATA );
  FSFormat( 0x82, 2, RFS_DATA );



 FSOpenFileSystem( SWAP_ON, CACHE_ON, 10000lu );


 // nothing to do...


 FSShutdownFileSystem();







 printf("\n\n Memory statistic:");

 if( FarFreeMemoryAtStart!=((unsigned long) farcoreleft()))
 {
  printf("\n  Deallocation ERROR:");
  Beep(); Beep(); Beep();
 }
 else
  Beep();

 printf(
        "\n  Far free at start: %lu"
        "\n  and now          : %lu"
        "\n\n"
        ,
        FarFreeMemoryAtStart,
        ((unsigned long) farcoreleft())
       );

 printf("\n Bye! \n\n");

 return 0;
}
开发者ID:dvorka,项目名称:rfs,代码行数:86,代码来源:main.cpp

示例2: main

void main()
{
do{
clrscr();
tab[0]=losowanie();
cout<<"\n\t";
textcolor(14);
cprintf("1");
textcolor(15);
cprintf(". Losowanie \"Du¾ego Lotka\"");
cout<<"\n\t";
textcolor(14);
cprintf("2");
textcolor(15);
cprintf(". Losowanie \"Expres Lotka\"");
cout<<"\n\t";
textcolor(14);
cprintf("3");
textcolor(15);
cprintf(". Losowanie \"Multi Lotka\"");
cout<<"\n\t";
textcolor(14);
cprintf("4");
textcolor(15);
cprintf(". Skre˜lanie kuponu");
cout<<"\n\t";
textcolor(14);
cprintf("5");
textcolor(15);
cprintf(". Wyj˜cie");

do{los=getch();}
while(los<49||los>53);
switch(los)
 {
 case '1':
 clrscr();
 if(kuponduzy)
 {textcolor(15);
 textbackground(0);
 cprintf("Tw¢j kupon: ");
 j=0;
 do{cout<<"\n\t"<<j+1<<". ";
    i=0;
    do{cout<<duzy[j][i];i++;
       if(i!=6){cout<<", ";}
      }
    while(i!=6);
    j++;
   }
 while(j!=5);
 i=0;
  do{ randomize();
     tab[i]=losowanie();j=0;
     while(j!=i||tab[i]==0)
          {if(tab[i]==tab[j]||tab[i]==0)
             {i--;j=i-1;}
              j++;
          }
     i++;
    }
  while(i!=6);
 cout<<"\n\nOto wylosowane liczby: ";
 i=0;
 do{cout<<tab[i];if(i!=5){cout<<", ";}i++;}
 while(i!=6);
 i=j=k=0;
 do{zak[i]=0;i++;}
 while(i!=5);
 i=0;
 do{
    if(duzy[j][i]==tab[k]){zak[j]++;}
    k++;
    if(k==6){i++;k=0;}
    if(i==6){j++;i=0;}
   }
 while(j!=6);
 i=0;
 cout<<"\n\n";
 do{cout<<"\t"<<i+1<<". "<<zak[i]<<" trafionych\n";i++;}
 while(i!=5);
 }
 else{cout<<"Nie masz skre˜lonego kuponu do Du¾ego Lotka.";}
 getch();
 break;

 case '2':
 clrscr();
 if(kuponexpres)
 {
 textcolor(15);
 textbackground(0);
 cprintf("Tw¢j kupon: ");
 j=0;
 do{cout<<"\n\t"<<j+1<<". ";
    i=0;
    do{cout<<expres[j][i];i++;
       if(i!=5){cout<<", ";}
      }
    while(i!=5);
//.........这里部分代码省略.........
开发者ID:noisy,项目名称:MyFirstProgramsFrom2003,代码行数:101,代码来源:totaliza.cpp

示例3: main

/*
 * main:
 *	Drive the sucker.  There are two main modes -- either we store
 *	the seek pointers, if the table is to be sorted or randomized,
 *	or we write the pointer directly to the file, if we are to stay
 *	in file order.  If the former, we allocate and re-allocate in
 *	CHUNKSIZE blocks; if the latter, we just write each pointer,
 *	and then seek back to the beginning to write in the table.
 */
int
main(int ac, char *av[])
{
    char *sp, *nsp, dc;
    FILE *inf, *outf;
    off_t last_off, pos, *p;
    size_t length;
    int first;
    uint32_t cnt;
    STR *fp;
    static char string[257];

    setlocale(LC_ALL, "");

    getargs(ac, av);		/* evalute arguments */
    dc = Delimch;
    if ((inf = fopen(Infile, "r")) == NULL) {
        perror(Infile);
        exit(1);
    }

    if ((outf = fopen(Outfile, "w")) == NULL) {
        perror(Outfile);
        exit(1);
    }
    if (!STORING_PTRS)
        fseek(outf, (long)sizeof(Tbl), SEEK_SET);

    /*
     * Write the strings onto the file
     */

    Tbl.str_longlen = 0;
    Tbl.str_shortlen = 0xffffffff;
    Tbl.str_delim = dc;
    Tbl.str_version = VERSION;
    first = Oflag;
    add_offset(outf, ftello(inf));
    last_off = 0;
    do {
        sp = fgets(string, 256, inf);
        if (sp == NULL || (sp[0] == dc && sp[1] == '\n')) {
            pos = ftello(inf);
            length = (size_t)(pos - last_off) -
                     (sp != NULL ? strlen(sp) : 0);
            last_off = pos;
            if (length == 0)
                continue;
            add_offset(outf, pos);
            if ((size_t)Tbl.str_longlen < length)
                Tbl.str_longlen = length;
            if ((size_t)Tbl.str_shortlen > length)
                Tbl.str_shortlen = length;
            first = Oflag;
        }
        else if (first) {
            for (nsp = sp; !isalnum((unsigned char)*nsp); nsp++)
                continue;
            ALLOC(Firstch, Num_pts);
            fp = &Firstch[Num_pts - 1];
            if (Iflag && isupper((unsigned char)*nsp))
                fp->first = tolower((unsigned char)*nsp);
            else
                fp->first = *nsp;
            fp->pos = Seekpts[Num_pts - 1];
            first = false;
        }
    } while (sp != NULL);

    /*
     * write the tables in
     */

    fclose(inf);
    Tbl.str_numstr = Num_pts - 1;

    if (Cflag)
        Tbl.str_flags |= STR_COMMENTS;

    if (Oflag)
        do_order();
    else if (Rflag)
        randomize();

    if (Xflag)
        Tbl.str_flags |= STR_ROTATED;

    if (!Sflag) {
        printf("\"%s\" created\n", Outfile);
        if (Num_pts == 2)
            puts("There was 1 string");
//.........这里部分代码省略.........
开发者ID:cyrilmagsuci,项目名称:freebsd,代码行数:101,代码来源:strfile.c

示例4: main

int main( void )
{
 dword FarFreeMemoryAtStart=(unsigned long)farcoreleft();

 printf("\n\n                        Reliable file system"
          "\n                                  by"
          "\n                            Jarda & Dvorka"
          "\n"
          "\n                 Compiled at %s, %s\n", __DATE__, __TIME__
       );
 printf(  "                  Starting with far heap: %luB \n", FarFreeMemoryAtStart );

 randomize();







 //- work with file system -

 #ifdef CREATE_EVERYTHING_NEW
  InitializeSimulation( TRUE, TRUE );   // create everything new

  FSCreatMasterBoot( 0x80, 512, 1 );
  FSCreatMasterBoot( 0x81, 512, 1 );
  FSCreatMasterBoot( 0x82, 512, 1 );

  // data stripe
  FSCreatPartition( 0x80, 1, 0, 500, ACTIVE_PARTITION  );
  // parity stripe
  FSCreatPartition( 0x80, 2, 501, 1023, NONACTIVE_PARTITION  );
  // data stripe
  FSCreatPartition( 0x81, 1, 0, 500, ACTIVE_PARTITION  );
  // swap party
  FSCreatPartition( 0x81, 2, 501, 1023, NONACTIVE_PARTITION  );
  // data stripe
  FSCreatPartition( 0x82, 1, 0, 500, ACTIVE_PARTITION  );
  // swap party
  FSCreatPartition( 0x82, 2, 501, 1023, NONACTIVE_PARTITION  );

  // format parties
  FSFormat( 0x80, 1, RFS_DATA );
  FSFormat( 0x80, 2, RFS_DATA  );
  FSFormat( 0x81, 1, RFS_DATA );
  FSFormat( 0x81, 2, RFS_SWAP );
  FSFormat( 0x82, 1, RFS_DATA );
  FSFormat( 0x82, 2, RFS_SWAP );

 #else
  InitializeSimulation();               // only init handles,...
 #endif



 // init file system ( inside init of cache )
 FSOpenFileSystem( SWAP_ON, CACHE_ON, 10000lu );







  #ifdef CACHE_TEST;

  word     PackageID=0,
           GetNumber=0,
           i;

  dword    Logical,
           Free;

  void far *Buffer=farmalloc(10*512); if( !Buffer ) exit(0);



  // allocates && creates package ( 0x81 or 1 - it has same effect )
  CacheManAllocateSector( 0x81, 1, 0, 1, Logical, GetNumber, PackageID, FPACK_CREAT );

  word j;
  word Number;


  // PackageID set in previous function
  for( i=1; i<=5; i++ )
  {
   // allocate allocates < logical, logical+6 >
   CacheManAllocateSector( 1, 1, 0lu, 7, Logical, GetNumber, PackageID, FPACK_ADD );


   printf("\n Get number: %u", GetNumber );

   // init buffer for save
   for( j=0; j<10*512; j++ ) ((byte far * )Buffer)[j]=0xCC;

   if( random(5) ) // probably add
    CacheManSaveSector( 1, 1, Logical, 7, PackageID, FPACK_ADD, Buffer );
   else
//.........这里部分代码省略.........
开发者ID:dvorka,项目名称:rfs,代码行数:101,代码来源:main.cpp

示例5: nsga2


//.........这里部分代码省略.........
    }
    
    // 
    global.nreal = nreal;
    global.nbin = nbin;
    global.nobj = nobj;
    global.ncon = ncon;
    global.popsize = popsize;
    global.pcross_real = pcross_real;
    global.pcross_bin = pcross_bin;
    global.pmut_real = pmut_real;
    global.pmut_bin = pmut_bin;
    global.eta_c = eta_c;
    global.eta_m = eta_m;
    global.ngen = ngen;
    global.nbits = nbits;
    global.min_realvar = min_realvar;
    global.max_realvar = max_realvar;
    global.min_binvar = min_binvar;
    global.max_binvar = max_binvar;
    global.bitlength = bitlength;  
    
    //
    nbinmut = 0;
    nrealmut = 0;
    nbincross = 0;
    nrealcross = 0;
    parent_pop = (population *)malloc(sizeof(population));
    child_pop = (population *)malloc(sizeof(population));
    mixed_pop = (population *)malloc(sizeof(population));
    allocate_memory_pop (parent_pop, popsize, global);
    allocate_memory_pop (child_pop, popsize, global);
    allocate_memory_pop (mixed_pop, 2*popsize, global);
    randomize();
    initialize_pop (parent_pop, global);
    
    // First Generation
    if (printout >= 1)
    {
		fprintf(fpt6,"\n\n Initialization done, now performing first generation");
    }
    decode_pop(parent_pop, global);
    evaluate_pop(parent_pop, global);
    assign_rank_and_crowding_distance (parent_pop, global);
    if (printout >= 1)
    {
		report_pop (parent_pop, fpt1, global);
		if (printout == 2)
		{
			fprintf(fpt4,"# gen = 1\n");
			report_pop(parent_pop,fpt4, global);
		}
		
		fprintf(fpt6,"\n gen = 1");
		
		fflush(fpt1);
		fflush(fpt2);
		fflush(fpt3);
		if (printout == 2)
		{
			fflush(fpt4);
		}
		fflush(fpt5);
		fflush(fpt6);
	}
    fflush(stdout);
开发者ID:hschilling,项目名称:pyOpt,代码行数:67,代码来源:nsga2.c

示例6: ssu

	ssu() {
		randomize();
	}
开发者ID:buynowforsale,项目名称:satoriya-shiori,代码行数:3,代码来源:ssu.cpp

示例7: main

void main() {

    clrscr();

    char d[7][8], a[17][14], path;
    int q = 0, i, j, col, row, pr = 15, pc = 1, cc = 1, cr = 15;

    y:
        for (i = 0; i < 7; i++) {
            for (j = 0; j < 7; j++) {
                if (i % 2 == 0)
                    d[i][j] = '~';
                else {
                    if (j % 2 == 0)
                        d[i][j] = '|';
                    else d[i][j] = ' ';
                }
            }
            d[i][7] = '\0';
        }

    randomize();
    cout << "player1" << endl;

    for (i = 0; i < 7; i++)
        puts(d[i]);

    x:
        cout << "enter COLUMN NUMBER" << endl;

    cin >> col;
    cout << "enter ROW NUMBER" << endl;
    cin >> row;

    /*const*/

    int r = 2 * row - 1, c = 2 * col - 1;

    if (r <= 0 || r >= 7 || c <= 0 || c >= 7) {
        cout << "invaLId re-ENteR ,,,,,,,,,,,,,,..:+{" << endl;
        goto x;
    }

    int l = random(6) + 1;
    d[r][c] = l + 48;
    clrscr();

    for (i = 0; i < 17; i++) {
        for (j = 0; j <= 12; j++) {
            if (i % 2 == 0)
                a[i][j] = '~';
            else {
                if (j % 2 == 0)
                    a[i][j] = '|';
                else
                    a[i][j] = ' ';
            }
        }
        a[i][13] = '\0';
    }

    int s = 0, k;
    a[pr][pc] = '*';

    if (q > 0)
        a[cr][cc] = '&';

    clrscr();

    for (i = 0; i < 17; i++) {
        if (i < 7)
            cout << d[i] << setw(27) << a[i] << endl;
        if (i >= 7)
            cout << setw(34) << a[i] << endl;
    }

    cout << endl << endl << endl << "ENTER THE PATH" << endl;

    z:
        cin >> path;
    s = 0;

    switch (path) {
        case 'u':
            for (i = pr; i > 0; i--) {
                if (a[i][pc] == ' ')
                    s++;
            }
            if (s <= l) {
                for (j = 1; j <= s; j++) {
                    a[pr - 2][pc] = a[pr][pc];
                    a[pr][pc] = ' ';
                    pr = pr - 2;
                }
                break;
            }
            else if (s > l) {
                for (j = 1; j <= l; j++) {
                    a[pr - 2][pc] = a[pr][pc];
                    a[pr][pc] = ' ';
//.........这里部分代码省略.........
开发者ID:CPP-Coders,项目名称:cb-school,代码行数:101,代码来源:sre.cpp

示例8: atoi


//.........这里部分代码省略.........
        }
        else if (level == 1) //super
        {
            cardPath = "img/UI/battle/UI_B_11.png";
            m_enemySpecialType = SUPER_ROCK;
        }
        else //ultra
        {
            cardPath = "img/UI/battle/UI_B_11-G.png";
            m_enemySpecialType = ULTRA_ROCK;
        }
    }
    else if (type == SISSORS)
    {
        if (level == 0) //normal
        {
            cardPath = "img/UI/battle/UI_B_09.png";
            m_enemySpecialType = SISSORS;
        }
        else if (level == 1) //super
        {
            cardPath = "img/UI/battle/UI_B_12.png";
            m_enemySpecialType = SUPER_SISSORS;
        }
        else //ultra
        {
            cardPath = "img/UI/battle/UI_B_12-G.png";
            m_enemySpecialType = ULTRA_SISSORS;
        }

    }
    else if (type == PAPER)
    {
        if (level == 0) //normal
        {
            cardPath = "img/UI/battle/UI_B_10.png";
            m_enemySpecialType = PAPER;
        }
        else if (level == 1) //super
        {
            cardPath = "img/UI/battle/UI_B_13.png";
            m_enemySpecialType = SUPER_PAPER;
        }
        else //ultra
        {
            cardPath = "img/UI/battle/UI_B_13-G.png";
            m_enemySpecialType = ULTRA_PAPER;
        }

    }

    //render enemy Special card
    m_enemySpecial = Sprite::create(cardPath);
    m_enemySpecial->setScale(m_Mag * 0.5);
    m_enemySpecial->setPosition(Vec2(m_visibleSize.width - m_enemySpecial->getBoundingBox().getMaxX() * 1.8, m_visibleSize.height - m_enemySpecial->getBoundingBox().getMaxY()));
    m_enemySpecial->setScale(m_Mag * 1.2);
    m_enemySpecial->setZOrder(10);
    m_instance->addChild(m_enemySpecial);

    auto smallenEnemy = ScaleTo::create(0.5, m_Mag*0.5);
    m_enemySpecial->runAction(Sequence::create(smallenEnemy, NULL));

    //-----------------------------------------------------------------------------------
    //Other Cards
    //-----------------------------------------------------------------------------------

    srand(time(NULL));
    for (int i = 0; i < 4; i++)
    {
        randomize(i);
        m_hiddenCards[i] = Sprite::create("img/UI/battle/UI_B_14.png");
        m_hiddenCards[i]->setPositionX(m_cards[i]->getPositionX() - 270);
        m_hiddenCards[i]->setScale(m_Mag*0.5);
        m_hiddenCards[i]->setPositionY(m_visibleSize.height - m_hiddenCards[i]->getBoundingBox().getMaxY());
        m_instance->addChild(m_hiddenCards[i]);
    }

    auto callback = CallFunc::create([this]() {
        this->displayUI();
    });

    MoveTo* appear[4];
    MoveTo* appearEnemy[4];
    for (int i = 0; i < 4; i++)
    {
        //player other cards animation
        appear[i] = MoveTo::create((4-i)*0.5, Vec2(m_cards[i]->getPosition().x, m_cards[i]->getPosition().y));
        auto wait = DelayTime::create(1.5);
        m_cards[i]->setPosition(m_cards[i]->getPosition().x, -m_cards[i]->getBoundingBox().getMaxY()*(4-i));
        if (i == 3)
            m_cards[i]->runAction(Sequence::create(appear[i], wait, callback, NULL));
        else
            m_cards[i]->runAction(appear[i]);

        //enemy other cards animation
        appearEnemy[i] = MoveTo::create(i * 0.5, Vec2(m_hiddenCards[i]->getPositionX(), m_hiddenCards[i]->getPositionY()));
        m_hiddenCards[i]->setPosition(m_hiddenCards[i]->getPositionX(), m_visibleSize.height + m_hiddenCards[i]->getBoundingBox().getMaxY() * i);
        m_hiddenCards[i]->runAction(appearEnemy[i]);
    }
}
开发者ID:riverreal,项目名称:MillionCode,代码行数:101,代码来源:PickingPhase.cpp

示例9: doPostOptionParseActions

void
doPostOptionParseActions( PomdpSolveParams params ) {
  /*
    Does more customized checking of the options to the program.
  */
  PomdpSolveProgOptions opts;
  char tmp_str[MAX_OPT_STRING_LEN];
  int idx;

  /* just for convenience within this routine */
  opts = params->opts;

  /****************/
   /* First see if a random number seed is given, and if it is set the
      seed to this value. */
  if( opts->rand_seed[0] != '\0' )
    setRandomSeedFromString( opts->rand_seed );

  /* Otherwise initialize the random number generator with
	psuedo-random seed. */
  else
    randomize();

  /****************/
  /* Set if we want to redirect everything to a file.  Note that we
	must do this early on and actually open the file here because we
	might shortly get error messages that will need to be printed
	out to the file. */
  if( opts->report_filename[0] != '\0' ) {

    if (( params->report_file
		= fopen( opts->report_filename , "w")) == NULL) {
	 params->report_file = stdout;
	 fprintf( gStdErrFile,
			"** Error: Cannot write to output file %s.\n",
			opts->report_filename );
	 fprintf( gStdErrFile,
			"\tUsing stdout instead.\n" );
    }  /* if can't open report file */

    /* If they desire to put all the output into a specific file,
	  then we will also output all stderr messages here as well. */
    gStdErrFile = params->report_file;

  } /* if redirecting output to a file */

  /****************/
  /* Try to make the prefix be the prefix of the POMDP file if the
	default is chosen. */
  if ( strcmp( opts->prefix_str, POMDP_SOLVE_OPTS_OPT_O_DEFAULT ) == 0 ) {

    strcpy( tmp_str, opts->param_filename );

    /* This will point to null term at first */
    idx = strlen( tmp_str );

    /* Start at the end and move left until we see the first
	  "period". */
    while (( idx > 0 ) && ( tmp_str[idx] != '.'))
	 idx--;

    /* Only override if we found a period in param filename */
    if ( idx > 0 ) {

	 /* Null terminate at the period */
	 tmp_str[idx] = '\0';

	 sprintf( opts->prefix_str, "%s-%d", tmp_str, getPid() );

    } /* if we can override the default */

  } /* if default prefix is being used */


    /* Start at the end of the param_filename string */

  /****************/
  /* Make sure nothing dips below some maximum precision setting. */

  enforceSmallestPrecision( &(opts->prune_epsilon),
                            POMDP_SOLVE_OPTS_ARG_PRUNE_EPSILON_STR );
  enforceSmallestPrecision( &(opts->epsilon),
                            POMDP_SOLVE_OPTS_ARG_EPSILON_STR );
  enforceSmallestPrecision( &(opts->lp_epsilon),
                            POMDP_SOLVE_OPTS_ARG_LP_EPSILON_STR );

  /* Don't want to have the LPs be less precise than the rest of the
     program's operations. More precise is alright, since it can
     filter things out, but less precise makes little sense. */
  if ( opts->lp_epsilon > opts->epsilon ) {

    Warning( "LP epsilon must be no greater than general epsilon." );

    opts->lp_epsilon = opts->epsilon;

  } /* if lp_epsilon greater than general epsilon */

  /* Set the global LP precision */
  LP_setPrecision( opts->lp_epsilon );

//.........这里部分代码省略.........
开发者ID:acgs,项目名称:pomdp-solve-5.4-YokooLab,代码行数:101,代码来源:params.c

示例10: randomize

double Random::real()
{
	// return a random real number in the range 0.0 to 1.0
	randomize();
	return double(_seed) / ULONG_MAX;
}
开发者ID:vmezhang,项目名称:StudyTest,代码行数:6,代码来源:random.cpp

示例11: TEST_CASE

#include "util/messagebox.hpp" // Include the message box functions
#include "util/files.hpp" // Include the file handling functions
#include "util/network.hpp" // Include the networking functions

#ifndef NDEBUG // Allow the NDEBUG to disable debug support at compile time

#define DOCTEST_CONFIG_IMPLEMENT
#include "doctest.h" // Include the required unit testing library which is a git submodule in lib/doctest

// Real number function assertions
TEST_CASE("real/random") {
	REQUIRE(random(20) < (unsigned int)20);
	REQUIRE(is_between((int)random_range(20, 40), 20, 40));
	REQUIRE(random_set_seed(5) == (unsigned int)5);
	REQUIRE(random_reset_seed() != (unsigned int)DEFAULT_RANDOM_SEED);
	REQUIRE(randomize() != (unsigned int)DEFAULT_RANDOM_SEED);
}
TEST_CASE("real/math") {
	REQUIRE(sign(5) == 1);
	REQUIRE(sign(0) == 0);
	REQUIRE(sign(-5) == -1);
	REQUIRE(sign(5.0) == 1);
	REQUIRE(sign(0.0) == 0);
	REQUIRE(sign(-5.0) == -1);
	REQUIRE(sqr(5) == 25);
	REQUIRE(sqr(5.0) == 25.0);
	REQUIRE(logn(5.0, 1.0) == 0.0);
	REQUIRE(logn(5.0, 5.0) == 1.0);
	REQUIRE(logn(5.0, 10.0) == doctest::Approx(1.431).epsilon(0.001));
	REQUIRE(degtorad(90.0) == doctest::Approx(PI/2.0));
	REQUIRE(degtorad(360.0) == doctest::Approx(2.0*PI));
开发者ID:piluke,项目名称:BasicEventEngine,代码行数:31,代码来源:util.cpp

示例12: randomize

Neuron::Neuron(int inputs,ActiveFunction* _func):inputCount(inputs),func(_func){
	threshold = 0.0;
	inputCount = std::max(1,inputCount);
	weight.resize(inputCount);
	randomize();
}
开发者ID:YJGit,项目名称:ArticleRecommendationSystem,代码行数:6,代码来源:neuron.cpp

示例13: main

/*
 * main:
 *	Drive the sucker.  There are two main modes -- either we store
 *	the seek pointers, if the table is to be sorted or randomized,
 *	or we write the pointer directly to the file, if we are to stay
 *	in file order.  If the former, we allocate and re-allocate in
 *	CHUNKSIZE blocks; if the latter, we just write each pointer,
 *	and then seek back to the beginning to write in the table.
 */
int
main(int ac, char *av[])
{
	char		*sp, dc;
	FILE		*inf, *outf;
	int32_t		last_off, length, pos;
	int32_t		*p;
	int		first, cnt;
	char		*nsp;
	STR		*fp;
	static char	string[257];

	getargs(ac, av);		/* evalute arguments */
	dc = Delimch;
	if ((inf = fopen(Infile, "r")) == NULL)
		err(1, "%s", Infile);

	if ((outf = fopen(Outfile, "w")) == NULL)
		err(1, "%s", Outfile);
	if (!STORING_PTRS)
		(void) fseek(outf, sizeof Tbl, SEEK_SET);

	/*
	 * Write the strings onto the file
	 */

	Tbl.str_longlen = 0;
	Tbl.str_shortlen = (unsigned int) 0xffffffff;
	Tbl.str_delim = dc;
	Tbl.str_version = VERSION;
	first = Oflag;
	add_offset(outf, ftell(inf));
	last_off = 0;
	do {
		sp = fgets(string, sizeof(string), inf);
		if (sp == NULL || (sp[0] == dc && sp[1] == '\n')) {
			pos = ftell(inf);
			length = pos - last_off - (sp ? strlen(sp) : 0);
			last_off = pos;
			if (!length)
				continue;
			add_offset(outf, pos);
			if (Tbl.str_longlen < (u_int32_t)length)
				Tbl.str_longlen = length;
			if (Tbl.str_shortlen > (u_int32_t)length)
				Tbl.str_shortlen = length;
			first = Oflag;
		}
		else if (first) {
			for (nsp = sp; !isalnum(*nsp); nsp++)
				continue;
			ALLOC(Firstch, Num_pts);
			fp = &Firstch[Num_pts - 1];
			if (Iflag && isupper(*nsp))
				fp->first = tolower(*nsp);
			else
				fp->first = *nsp;
			fp->pos = Seekpts[Num_pts - 1];
			first = FALSE;
		}
	} while (sp != NULL);

	/*
	 * write the tables in
	 */

	(void) fclose(inf);
	Tbl.str_numstr = Num_pts - 1;
	if (Tbl.str_numstr == 0)
		Tbl.str_shortlen = 0;

	if (Oflag)
		do_order();
	else if (Rflag)
		randomize();

	if (Xflag)
		Tbl.str_flags |= STR_ROTATED;

	if (!Sflag) {
		printf("\"%s\" created\n", Outfile);
		if (Tbl.str_numstr == 1)
			puts("There was 1 string");
		else
			printf("There were %u strings\n", Tbl.str_numstr);
		printf("Longest string: %lu byte%s\n",
			  (unsigned long) Tbl.str_longlen,
		       Tbl.str_longlen == 1 ? "" : "s");
		printf("Shortest string: %lu byte%s\n",
			  (unsigned long) Tbl.str_shortlen,
		       Tbl.str_shortlen == 1 ? "" : "s");
//.........这里部分代码省略.........
开发者ID:lattera,项目名称:openbsd,代码行数:101,代码来源:strfile.c

示例14: main

void main()
{
	FILE *f;
	char c;
	char pass[16] = "\0", RealPass[16] = "hg";

	for (int k = 1; k < 27; k++)
		pus[k] = 1;

	if ((f = fopen("dict.dat", "r")) == NULL)
	{
		cprintf("Error opening dictionary file.");
		getch();
		return;
	}

	s[0] = '\0';
	randomize();
	/*int zz = random(3548);
	for (k = 0; k < zz; k++)
		fgets(s, 20, f);
	*/
	fgets(s, 20, f);
	s[strlen(s)] = '\0';
	fclose(f);

	textbackground(BLACK);
	clrscr();

	randomize();
	textcolor(LIGHTGRAY);
	for (int i = 0; i < 170; i++)
	{
		gotoxy(random(80), random(25));
		cprintf("њ");
	}
	textbackground(BLUE);
	textcolor(CYAN);
	window(20, 9, 60, 15);
	clrscr();
	window(1, 1, 80, 25);

	gotoxy(20, 9);
	cprintf("к");
	for (i = 0; i < 39; i++)
		cprintf("Ф");
	cprintf("П");
	for (i = 10; i < 15; i++)
	{
		gotoxy(20, i);
		cprintf("Г");
		gotoxy(60, i);
		cprintf("Г");
	}
	gotoxy(20, 15);
	cprintf("Р");
	for (i = 1; i < 40; i++)
		cprintf("Ф");
	cprintf("й");

	textbackground(BLACK);
	textcolor(RED);
	gotoxy(22, 16);
	for (i = 1; i <= 40; i++)
	{
		cprintf("л");
	}
	for (i = 10; i < 16; i++)
   {
      gotoxy(61, i);
      cprintf("л");
   }

   textbackground(BLUE);
   textcolor(GREEN);
   gotoxy(30, 12);
   cprintf("Parola : ");
   textcolor(BLACK);
   cprintf("ллллллллллллллл");
   textbackground(BLACK);
   textcolor(LIGHTGREEN);
   gotoxy(39, 12);
   c = getch();
   i = 1;
   while ((c != 13) && (i < 15))
   {
      cprintf("*");
      char *aux, *aux1;
      aux1 = aux = new char;
      aux = &c;
      strcat(pass, aux);
      pass[i] = '\0';
      delete aux1;
		c = getch();
		i++;
	}
	i = 0;
	if (!strcmp(pass, RealPass))
	{
		textbackground(BLACK);
//.........这里部分代码省略.........
开发者ID:bdumitriu,项目名称:playground,代码行数:101,代码来源:hangman.cpp

示例15: main

int main(int argc, char** argv)
{
    unsigned long bit, i;
    char* bitfield = CreateBitField(100);
    
    randomize();
    
    for (i=0; i<20; i++)
    {
	do
	{
	    bit = random(100);	    
	    
	} while (GetBitfieldBit(bitfield, bit));
	
	SetBitfieldBit(bitfield, bit);
	printf("%d\n", bit);		
    }
    
    printf("De getallen gesorteerd:\n");
    
    for (i=0; i<100; i++) 
    {
	if (GetBitfieldBit(bitfield, i))
	    printf("%d\n", i);	
    }
    
    DestroyBitfield(bitfield);
    
    printf("---------------------------------\n");
    
    
    bitfield = CreateBitField(100);
    
   
    for (i=0; i<20; i++)
    {
	do
	{
	    bit = random(50);	    
	    
	} while (GetBitfieldBit(bitfield, bit));
	
	SetBitfieldBit(bitfield, bit);
	printf("%d\n", bit+50);		
    }
	
     //printf("/////////////////////////////////\n");
    
    for (i=0; i<50; i++) 
    {
	if (GetBitfieldBit(bitfield, i))
	{
	//    printf("%lu::%lu\n", i, (i+50));
	    SwapBitfieldBits(bitfield, i, (i+50));
	}
    }
    
     //printf("/////////////////////////////////\n");
    

    printf("De getallen gesorteerd:\n");
      
    for (i=0; i<100; i++) 
    {
	if (GetBitfieldBit(bitfield, i))
	    printf("%d\n", i);	
    }

    
    DestroyBitfield(bitfield);    
}
开发者ID:CivilPol,项目名称:sdcboot,代码行数:72,代码来源:bitfield.c


注:本文中的randomize函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。