int main(void) { // seed a random value so function rand() won't return the same value seedRand(); // call the displayCards function which starts the game displayCards(); return 0; }
int initMap(int sx, int sy){ seedRand(); BSP *test = bspNewSized(0, 0, sy, sx); bspSplitRecursive(test, 5, 5, 5); MAPROOT = (struct TILE *)malloc(sizeof(struct TILE)); if(MAPROOT == NULL) return ERR_MALLOC; MAPCURRENT = MAPROOT; int x, y; for(y = 0; y < sy; y++){ for(x = 0; x < sx; x++){ MAPCURRENT->tX = x; MAPCURRENT->tY = y; if(MAPCURRENT->tX == 0 || MAPCURRENT->tX == sx - 1 || MAPCURRENT->tY == 0 || MAPCURRENT->tY == sy - 1){ MAPCURRENT->tT = TILE_WALL; } else{ MAPCURRENT->tT = TILE_ROCKFLOOR; } if(y == sy - 1 && x == sx - 1){ MAPTAIL = MAPCURRENT; return ERR_NONE; } else{ MAPCURRENT->next = (struct TILE *)malloc(sizeof(struct TILE)); if(MAPCURRENT->next == NULL) return ERR_MALLOC; MAPCURRENT = MAPCURRENT->next; } } } return ERR_NONE; }
void HtlMLCGenerator::initialize(void) { //initialize the seeding value seedRand(); //initialize the streams nextStream(); return; };
int main(void) { uintptr_t i, j, q; char * zstr; char * zary[N_z]; Sarq * s1 = SarqMalloc(NULL); /* Using default SarqType */ SarqType sarqInfo = { compareFunc, printFunc, freeFunc }; Sarq * s2 = SarqMalloc(&sarqInfo); /* s1 default SarqType tests */ for (i = 0; i < N; i += 10) { SarqInsert(s1, (void *) i); /* insert N times */ } printf("\n=========================\nsize: %d\n", (int) SarqSize(s1)); SarqPrint(stdout, s1); for (i = 0; i < N/5; i += 10) { /* remove N/3 items */ q = (uintptr_t) SarqRemove(s1); } printf("\n=========================\nsize: %d\n", (int) SarqSize(s1)); printf("depth: %d\n", (int) SarqDepth(s1)); SarqPrint(stdout, s1); printf("\n=========================\n"); seedRand(); for (i = 0; i < N_z; ++i) { q = getRandLen(31) + 1; zstr = malloc(32*sizeof(char)); for (j = 0; j < q; ++j) zstr[j] = 'A' + getRandLen(26); zstr[q] = '\0'; zary[i] = zstr; SarqInsert(s2, (void*) zstr); } printf("\n=========================\nsize: %d\n", (int) SarqSize(s2)); printf("depth: %d\n", (int) SarqDepth(s2)); SarqPrint(stdout, s2); printf("\n"); for (i = 0; i < N_z/3; ++i) { printf("/%s/ : ", (char *) SarqRemove(s2)); } printf("\n=========================\nsize: %d\n", (int) SarqSize(s2)); printf("depth: %d\n", (int) SarqDepth(s2)); for (i = 0; i < N_z; ++i) free(zary[i]); printf("\n"); SarqFree(s1); SarqFree(s2); return 0; }
void generateKey(RSAint p, RSAint q, RSAint* e, RSAint* d, RSAint* n) { assert(e != NULL && d != NULL && n != NULL && p > minPrimeLimit && p < maxPrimeLimit && q > minPrimeLimit && q < maxPrimeLimit && p != q); *n = p*q; RSAint eFunc = (p-1)*(q-1); seedRand(); *e = randomPrime(2,eFunc); while(gcd(*e,eFunc) != 1) { *e = randomPrime(2,eFunc); } *d = multiplicative_inverse(*e,eFunc); assert((*n == p*q) && (*e**d % ((p-1)*(q-1)) == 1) && (*e > 10000)); }
TorrentCreator::TorrentCreator() : m_pIPData(NULL), m_nLastAutoID(0), m_pInfoBuffer(NULL), m_nInfoBufferSize(0) { seedRand(); // Open the temp buffer file if( !m_tempOutputFile.Open( "\\BTTorrentGenerator\\OutputData.tmp", CFile::modeCreate | CFile::modeReadWrite | CFile::shareDenyWrite ) ) { TRACE( "Error opening \"\\BTTorrentGenerator\\OutputData.tmp\" temp buffer file\n" ); MessageBox( NULL, "Error opening\n\"c:\\BTTorrentGenerator\\OutputData.tmp\"\ntemp buffer file", "No Temp File", MB_ICONEXCLAMATION | MB_OK ); AfxAbort(); return; } // Open the data file that is used to generate hashes, if it is not open already if( !m_decoyDataFile.Open( "\\syncher\\rcv\\plug-ins\\BTTorrentGenerator\\TorrentDecoyFile", CFile::modeRead | CFile::shareDenyWrite ) ) { TRACE( "Error opening input decoy data file\n" ); MessageBox( NULL, "Could not open decoy data file", "No Data File", MB_ICONEXCLAMATION | MB_OK ); AfxAbort(); return; } }
SSL *SslContext::newSSL() { init(m_iMethod); seedRand(128); return SSL_new(m_pCtx); }
//############################ INSTANCE OF FITNESS ARRAY!!!!! MODIFY ONCE FITNESS ARRAY BUILDER COMPLETE #################################### void reproduction(int *demeIndexes) { int i, j, n, count, dadi, momi, *ipt; short int *offspringGenotyes, *sipt; int *offspringDemeLocations; count = 0; offspringGenotyes = (short int *) malloc( (sizeof(short int) * 2 * totalSitesInGenome * TOTAL_N) ); offspringDemeLocations = (int *) malloc( (sizeof(int) * TOTAL_N) ); selectionCoefficients = (double *) malloc( (sizeof(double)*totalSitesInGenome)); sipt = offspringGenotyes; ipt = demeIndexes; for ( i = 0; i < nDEMES; i++ ) { n = demeCounts[i]; // set up fitness array for choosing parents if ( MODEL_TYPE == MODEL_TYPE_SELECTION ) buildFitnessArray(ipt, i, n );// buildFitnessArray uses addres else if ( MODEL_TYPE != MODEL_TYPE_NEUTRAL_ONLY ) { fprintf(stderr, "\nError in reproduction()! MODEL_TYPE (= %i) not recognized!\n", MODEL_TYPE); exit(-1); } // choose parents n times and make n offspring for ( j = 0; j < n; j++ ) { momi = pickParent( &selectionCoefficients[0], -1, n ); // -1 = flag for parent not chosen yet dadi = pickParent( &selectionCoefficients[0], momi, n ); momi = *(ipt + momi); // extract the right index from the overall index array; "momi" and "dadi" are "local" indexes in the consecutive fitness array dadi = *(ipt + dadi); // /* // test check: // if ( demeLocations[momi] != i || demeLocations[dadi] != i ) { // fprintf(stderr, "\nError in reproduction():\n\tLocations of parents not in right deme!\n\tdadi = %i, momi = %i\n", dadi, momi); // fprintf(stderr, "i = %i, demeLocations[momi] = %i, demeLocations[dadi] = %i\n\n", i, demeLocations[momi], demeLocations[dadi]); // exit(-1); // } // // */ // end test check makeOffspring(momi, dadi, sipt); sipt += 2 * totalSitesInGenome; // 2 for diploid; advance to next spot to start storing offspring genotype offspringDemeLocations[count] = i; count++; } ipt += TOTAL_N; // advance deme index pointer to next deme's set } if ( count != TOTAL_N ) { fprintf(stderr, "\nError in reproduction()! Made wrong number of offspring!\n\tcount (=%i) != TOTAL_N (= %i)\n", count, TOTAL_N); exit(-1); } free(genotypes); genotypes = offspringGenotyes; free(demeLocations); demeLocations = offspringDemeLocations; // // test check: // count = 0; // for ( i = 0; i < nDEMES; i++ ) { // for ( j = 0; j < demeCounts[i]; j++ ) { // if ( demeLocations[count] != i ) { // fprintf(stderr, "\nError in reproduction():\n\tOffspring count by location not consistent.\n"); // fprintf(stderr, "deme = %i, demeCounts[%i] = %i, j = %i, count = %i, demeLocations[count] = %i\n", i, i, demeCounts[i], j, count, demeLocations[count]); // exit(-1); // } // count++; // } // } // // end test check //} void RNGsetup(void) { int seed, rcount; FILE *fpt; int stime; long ltime; FILE *rseed; long int i; if (DETERMINISTIC) { fpt = fopen("RnumSeed.txt","r"); if (fpt == NULL) { perror("Can't open RnumSeed.txt"); exit(-1); } rcount = fscanf(fpt,"%i",&seed); if ( rcount ) { seedRand(seed); // fixed random number seed fclose(fpt); } else { fprintf(stderr, "\n\n\tError! nothing read from file! Exiting!\n\n"); exit(-1); } //fprintf(stderr, "\n\nSeed = %i\n\n",seed); } else { /* use calendar time to seed random number generator. Code adopted from Schildt's textbook */ /* get the calendar time */ ltime=time(NULL); stime=(unsigned) ltime/2; // generate and store random number seed rseed = fopen("RnumSeed.txt","w"); fprintf(rseed,"%i\n",stime); fclose(rseed); seedRand(stime); // get random number seed (system time) } // warm up for ( i = 0; i < 1000000; i++ ) randU(); }
UINT ClientReceiverThreadProc(LPVOID pParam) { // Init message window handle if( pParam == NULL ) return (UINT)-1; seedRand(); // Copy data from the param to the locals HWND hwnd = (HWND)pParam; // Create the listening socket, but do not open it ListeningSocket listener( hwnd ); // Link event into events array WSAEVENT aEvents[CLIENTRECEIVER_RESERVED_EVENTS+1]; for( int i = 0; i < CLIENTRECEIVER_RESERVED_EVENTS; i++ ) { aEvents[i] = WSACreateEvent(); if( aEvents[i] == WSA_INVALID_EVENT ) return (UINT)-1; } aEvents[CLIENTRECEIVER_RESERVED_EVENTS] = listener.ReturnEventHandle(); // Critical variables ListeningSocket::ListenerStatus eCriticalStatus; // Threaddata variables ClientReceiverThreadData threadData; memcpy( threadData.m_aReservedEvents, aEvents, sizeof(WSAEVENT) * CLIENTRECEIVER_RESERVED_EVENTS ); threadData.m_peStatus = &eCriticalStatus; CCriticalSection criticalSection; // request initialization of the thread data ::PostMessage( hwnd, WM_LISTENER_INIT_THREAD_DATA, (WPARAM)&criticalSection, (LPARAM)&threadData ); WSANETWORKEVENTS events; // what the fired event data was DWORD event; // which event fired char *pLogMsg = NULL; while(true) { event = WSAWaitForMultipleEvents( (CLIENTRECEIVER_RESERVED_EVENTS + 1), aEvents, false, WSA_INFINITE, false ); char buf[16]; _itoa( event, buf, 10 ); if( event == WSA_WAIT_FAILED ) AfxAbort(); // exit event if( event == 0 ) { CSingleLock singleLock( &criticalSection, true ); WSAResetEvent( aEvents[event] ); break; } // change status if( event == 1 ) { CSingleLock singleLock( &criticalSection, true ); switch( eCriticalStatus ) { case ListeningSocket::OPEN: listener.Open(); break; case ListeningSocket::CLOSED: listener.Close(); break; } WSAResetEvent( aEvents[event] ); } // socket event if( event >= CLIENTRECEIVER_RESERVED_EVENTS ) { WSAResetEvent( aEvents[event] ); events = listener.ReturnNetworkEvents(); if(events.lNetworkEvents & FD_CONNECT) { listener.OnConnect(events.iErrorCode[FD_CONNECT_BIT]); } if(events.lNetworkEvents & FD_READ) { while( listener.OnReceive(events.iErrorCode[FD_READ_BIT]) ); } if(events.lNetworkEvents & FD_WRITE) { listener.OnSend(events.iErrorCode[FD_WRITE_BIT]); } if(events.lNetworkEvents & FD_CLOSE) { listener.OnClose(events.iErrorCode[FD_CLOSE_BIT]); } if(events.lNetworkEvents & FD_ACCEPT) { listener.OnAccept(events.iErrorCode[FD_ACCEPT_BIT]); } } } // end while(1) // Close the reserved events for( int i = 0; i < CLIENTRECEIVER_RESERVED_EVENTS; i++ ) WSACloseEvent( aEvents[i] ); // close the socket listener.Close(); return 0; // exit the thread }