int main(int argc, char *argv[]) { int N = ((argc == 2) ? atoi(argv[1]) : 1) - 1; while (N--) { gen_random(100.0); } printf("%.9f\n", gen_random(100.0)); return(0); }
void init_own_statistics(void){ player.oldlocation[0] = gen_random(PITCH_LENGTH); player.oldlocation[1] = gen_random(PITCH_WIDTH); player.newlocation[0] = player.oldlocation[0]; player.newlocation[1] = player.oldlocation[1]; player.kicked = -1; player.reached = -1; player.ball_challenge = -1; }
int main(int argc, char **argv) { srand(time(NULL)); printf("/* ------------------------- */\n"); printf("/* Random Test Smithy Logic */\n"); printf("/* ------------------------- */\n\n"); // Defining variables struct gameState *gamestate = newGame(); // Hold the game state int kCard[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, sea_hag, tribute, smithy}; int i; // Loop irritater int j; // Loop irritater int currentplayer; int choise1 = -1; int choice2 = -1; int choice3 = -1; int handPos = 0; int bonus = 0; int result = 0; int test_pass = 1; // 0 == false: failing test, 1 == true: all test passed for (i = 0; i < gen_random(0, 100); i++) { // number of random games to be tested initializeGame(gen_random(2, 4), kCard, gen_random(1, 9), gamestate); currentplayer = gamestate->whoseTurn; // Initialize and get current player for (j = 0; j < 1000; j++) { // number of test to run for current initialized game. result = cardEffect(smithy,choise1, choice2, choice3, gamestate, handPos, &bonus); if (result != 0) { printf("Error: Expected [%d] Garend[%d]\n", -1, result); test_pass = 0; } gamestate->outpostPlayed = 0; gamestate->phase = 0; gamestate->numActions = 1; gamestate->numBuys = 1; gamestate->playedCardCount = 0; gamestate->whoseTurn = gen_random(2, gamestate->numPlayers); gamestate->handCount[gamestate->whoseTurn] = 0; } } if (test_pass) { printf("All test have passed. \n"); } return 0; }
void test_correctness_set_then_get(){ std::cout << "Running test [test_correctness_set_then_get]..." << std::endl; const int NTEST = 100; char key[129]; char value[2049]; char value2[2049]; for(int i=0;i<NTEST;i++){ gen_random(key, 128); gen_random(value, 2018); kv739_put(key, value, value2); kv739_get(key, value2); assert(strcmp(value, value2) == 0); } std::cout << "Finished test [test_correctness_set_then_get]!" << std::endl; }
ExImage ExImage::operator=(const ExImage& src) { this->full_path = src.getFullPath(); this->win_name = src.getBasename() + gen_random(); this->img_mat = src.getMat(); return *this; }
void SetPlayerName() { std::cout << "SetPlayerName()\n"; char NameRandom[24]; gen_random(NameRandom, 3); PlayerName = "Dark" + std::string(NameRandom) +"Player"; }
static void test_set_content_property_again(gs_grid_storage_t * gs) { gs_error_t **err = NULL; gchar **result = NULL; char *nameRef = test_init(gs, "Ref_linked", NULL); char *nameCont = gen_random(7); gs_container_t *container = container_init(gs, nameCont); hc_ul_content_from_file(gs, nameCont, "Content", "file_test.txt", err); gs_content_t *content = gs_get_content_from_path(container, "Content", err); char *props = "key1=value1"; char *props2 = "key1=value2"; hc_set_content_property(content, &props, err); hc_set_content_property(content, &props2, err); g_assert_true(err == NULL); hc_get_content_properties(content, &result, err); if (strcmp(result[0], "key1=value2")) g_test_fail(); gs_content_free(content); test_end(gs, nameRef, container); }
void main() { int i,n,a[2000]; struct timeval tv; FILE *fp; fp=fopen("graph.txt","w"); double end,start,elapse; for(i=100;i<=1000;i=i+100) { gen_random(a,i); gettimeofday(&tv,NULL); start=tv.tv_sec+(tv.tv_usec/1000000.0); mergesort(a,0,i-1); gettimeofday(&tv,NULL); end=tv.tv_sec+(tv.tv_usec/1000000.0); elapse=end-start; printf("i=%d \t elapse=%lf \n",i,elapse); fprintf(fp,"%d\t%lf\n",i,elapse); } fclose(fp); system ("gnuplot"); }
UserPoseData::UserPoseData(std::vector<tf::StampedTransform> & transforms_,std::string name) { if(name == "") { char buffer[10]; gen_random(buffer,8); name=std::string(buffer); } this->name = name; //ci sarebbe da correggere i valori transforms.clear(); transforms.push_back(transforms_[0]); transforms.push_back(transforms_[0].inverse()*transforms_[1]); transforms.push_back(transforms_[2]); transforms.push_back(transforms_[2].inverse()*transforms_[3]); transforms.push_back(transforms_[3].inverse()*transforms_[4]); transforms.push_back(transforms_[1].inverse()*transforms_[5]); std::vector<float> gomito_dx = extractAngles(transforms[3].getRotation(),"yzx"); std::cout <<"gomito: " << gomito_dx[0] <<" "<<gomito_dx[1]<<" "<<gomito_dx[2]<<std::endl; }
Connection::Connection(int desc, WSProtocol * proto) : socket ( desc ) { protocol = proto; char randstr[11]; gen_random ( randstr, 10 ); uniqueID = randstr; buffer = ""; }
int test_control(int n){ int counter = 0; for (int k = 0;k<n;k++){ uint8_t msg[256]; float t1 = gen_random(0.0,1.0), h1 = gen_random(-1.0,1.0), t=0, h=0; int8_t flag; flag = esp_pack_control(msg,h1,t1); printf("Raw: rudder = %g, speed = %g\n",h1,t1); printf("Packed %d bytes into message\n",flag); if (esp_unpack_control(msg,&h,&t) > 0){ printf("Message: rudder = %g, speed = %g\n",h,t); counter++; } } return counter; }
int test_gps(int n){ int counter = 0; for (int k = 0;k<n;k++){ uint8_t msg[256]; int32_t lon1 = int32_t(1e7*gen_random(-180.0,180.0)), lat1 = int32_t(1e7*gen_random(-180.0,180.0)), lon=0,lat=0; float t1 = gen_random(0.0,1.0e6), t=0; int8_t flag; flag = esp_pack_gps(msg,lon1,lat1,t1); printf("Raw: lon = %ul, lat = %ul, t=%f\n",lon1,lat1,t1); printf("Packed %d bytes into message\n",flag); if (esp_unpack_gps(msg,&lon,&lat,&t) > 0){ printf("Message: lon = %dl, lat = %dl, t=%f\n",lon,lat,t); counter++; } } return counter; }
char selectRandom (struct aminoacids * genelist, int count) { STATIC int i, lo, hi; #ifdef STATIC static double r; r = gen_random (1); #else double r = gen_random (1); #endif if (r < genelist[0].p) return genelist[0].c; lo = 0; hi = count-1; while (hi > lo+1) { i = (hi + lo) / 2; if (r < genelist[i].p) hi = i; else lo = i; } return genelist[hi].c; }
void sampChatFlood() { if(GetTickCount() - dwLastChatFlood >= settings.uiChatFloodInterval) { char szRandomMessage[60 + 1]; gen_random(szRandomMessage, 60); sendChat(szRandomMessage); dwLastChatFlood = GetTickCount(); } }
void sampSpam() { if(GetTickCount() - dwLastDisconnection >= settings.uiSpamInterval) { gen_random(g_szNickName, rand()%16+3); iGettingNewName = true; sampDisconnect(0); resetPools(1, 1); dwLastDisconnection = GetTickCount(); } }
void test_throughput_get(){ std::cout << "Running test [test_throughput_get]..." << std::endl; const int NTEST = 100; char * keys = new char[129*NTEST]; char value[2049]; char value2[2049]; for(int i=0;i<NTEST;i++){ gen_random(&keys[i*129], 128); gen_random(value, 2018); kv739_put(&keys[i*129], value, value2); } Timer t; for(int i=0;i<NTEST;i++){ kv739_get(&keys[i*129], value2); } double elapsed = t.elapsed(); std::cout << "Finished test [test_throughput_get]!" << std::endl; std::cout << " Throughput of get: " << (1.0*NTEST/elapsed) << " puts/secs..." << std::endl; }
static void test_set_container_quota(gs_grid_storage_t * gs) { char *nameRef = test_init(gs, "Ref_linked", NULL); char *nameCont = gen_random(7); gs_container_t *container = container_init(gs, nameCont); gs_error_t *err2 = hc_set_container_quota(container, "test"); g_assert_true(err2 == NULL); test_end(gs, nameRef, container); }
static void test_del_container_versioning_void(gs_grid_storage_t * gs) { char *nameRef = test_init(gs, "Ref_linked", NULL); char *nameCont = gen_random(7); gs_container_t *container = container_init(gs, nameCont); gs_error_t *err = hc_del_container_versioning(container); g_assert_true(err == NULL); test_end(gs, nameRef, container); }
// Encrypts plaintext ptxt, stores as ciphertext ctxt void encrypt_phrase(dheluks_ctx_t *ctx, dheluks_pkg_t *pkg, dheluks_kys_t *skr, dheluks_txt_t *txt) { chacha_poly1305_set_key(&ctx->ciph, skr->sharekey); //set key gen_random(&ctx->rand, NONCE_SIZE, pkg->nonce); //generate nonce chacha_poly1305_set_nonce(&ctx->ciph, pkg->nonce); //set nonce chacha_poly1305_encrypt(&ctx->ciph, pkg->csize, pkg->cphtxt, txt->plntxt); //encrypt chacha_poly1305_digest(&ctx->ciph, DIGEST_SIZE, pkg->digest); }
int main(void) { srand(time(NULL)); // 1. 生成一系列的随机数并保存到数组中 for (int i = 0; i < ARRAYSIZE; i++) { randArray[i] = gen_random(10); } // 2. 统计每个数字出现的次数,并打印 for (int j = 0; j < 10; j++) { printf("%d's count: %d\n", j, howmany(j)); } return 0; }
static void test_set_container_storage_policy_wrong(gs_grid_storage_t * gs) // to be improved { char *nameRef = test_init(gs, "Ref_linked", NULL); char *nameCont = gen_random(7); gs_container_t *container = container_init(gs, nameCont); gs_error_t *err = hc_set_container_storage_policy(container, "Wrong_stgpol"); if (err == NULL) g_test_fail(); test_end(gs, nameRef, container); }
int main(int argc, char *argv[]) { Hashtable* ht = newStrHashTable(); char buff[100]; int i; char str[10] = "thisis0"; char object[90] = "this is a shared object"; size_t sizeobject = sizeof(char) * 90; for (i = 0; i < 18; i++) { str[6] = '0'+(i%10); strhh_insert(ht, str, (void**)&object, &sizeobject); } printf("All\n"); printAll(ht); for (i = 0; i < 18; i++) { str[6] = '0'+(i%10); strhh_remove(ht, str, (void**)&object, &sizeobject); } printf("none\n"); printAll(ht); strhh_insert(ht, "Test", (void**)&object, &sizeobject); strhh_insert(ht, "TesT", (void**)&object, &sizeobject); strhh_insert(ht, "TeSt", (void**)&object, &sizeobject); strhh_insert(ht, "TEst", (void**)&object, &sizeobject); strhh_insert(ht, "test", (void**)&object, &sizeobject); assert(strhh_contains(ht, "Test", (void**)&object, &sizeobject)); assert(strhh_contains(ht, "Test", (void**)&object, &sizeobject)); assert(strhh_contains(ht, "TEst", (void**)&object, &sizeobject)); assert(strhh_contains(ht, "TesT", (void**)&object, &sizeobject)); assert(strhh_contains(ht, "TeSt", (void**)&object, &sizeobject)); assert(!strhh_contains(ht, "TEST", (void**)&object, &sizeobject)); assert(!strhh_contains(ht, "T778ST", (void**)&object, &sizeobject)); printf("Test\n"); printAll(ht); for (i = 0; i < 10000; i++) { gen_random(buff, 90); strhh_insert(ht, buff, (void**)&object, &sizeobject); } strhh_remove(ht, "|||blubla##", (void**)&object, &sizeobject); freehashtable(ht); freepool(); return 0; }
char selectRandom (const struct aminoacids * genelist, int count) { double r = gen_random (1); int i, lo, hi; if (r < genelist[0].p) return genelist[0].c; lo = 0; hi = count-1; while (hi > lo+1) { i = (hi + lo) / 2; if (r < genelist[i].p) hi = i; else lo = i; } return genelist[hi].c; }
int main(int argc, char **argv) { std::vector<vector> points(LEN); gen_random(points); SpatialHash<vector> hash(10000.0f/LEN); TIME_IT(hash.insert(points)); #ifdef NOGUI TIME_IT(query_test(points, hash)); #else QApplication a(argc, argv); MainWindow w(&hash); w.show(); return a.exec(); #endif }
static void test_set_content_storage_policy_bad_path(gs_grid_storage_t * gs) // to be improved { gs_error_t **err = NULL; char *nameRef = test_init(gs, "Ref_linked", NULL); char *nameCont = gen_random(7); gs_container_t *container = container_init(gs, nameCont); hc_set_content_storage_policy(container, "Content", "TWOCOPIES", err); if (err == NULL) g_test_fail(); test_end(gs, nameRef, container); }
Client::Client(clientParams* params) { sd = params->sd; profileid = 0; userid = 0; game = NULL; authenticated = false; ip = params->peer.sin_addr.s_addr; lastPacket = time(NULL); sesskey = time(NULL) * rand(); if(sesskey < 0) sesskey = -sesskey; memset(&challenge,0,sizeof(challenge)); gen_random(challenge,10); gameInProgress = false; formatSend(sd,true,2,"\\lc\\1\\challenge\\%s\\id\\1",challenge); free((void *)params); }
static void test_set_content_storage_policy(gs_grid_storage_t * gs) { gs_error_t **err = NULL; char *nameRef = test_init(gs, "Ref_linked", NULL); char *nameCont = gen_random(7); gs_container_t *container = container_init(gs, nameCont); hc_ul_content_from_file(gs, nameCont, "Content", "file_test.txt", err); gs_content_t *content = gs_get_content_from_path(container, "Content", err); hc_set_content_storage_policy(container, "Content", "TWOCOPIES", err); g_assert_true(err == NULL); gs_content_free(content); test_end(gs, nameRef, container); }
int main(int argc, char *argv[]) { int N = ((argc == 2) ? atoi(argv[1]) : 1); double *ary; int i; /* create an array of N random doubles */ ary = (double *)malloc((N+1) * sizeof(double)); for (i=1; i<=N; i++) { ary[i] = gen_random(1); } heapsort(N, ary); printf("%.10f\n", ary[N]); free(ary); return(0); }
int main() { int n; int upper; char src_buf[1024]; char dst_buf[1024]; printf("Please input sum: "); scanf("%d", &upper); calc_sum(&n, upper); gen_random(src_buf, sizeof(src_buf)); /* Copy to local buffer */ buf_cpy(dst_buf, src_buf, sizeof(dst_buf)); /* Copy to global buffer */ buf_cpy(g_buf, src_buf, sizeof(g_buf)); return 0; }
void players_action(void){ extern int rank, ball[2]; extern int dribb; int mult; if(ENG_RANKS(rank) || BRA_RANKS(rank)){ chase_ball_action(); // go after ball if(player.newlocation[0] == ball[0] && player.newlocation[1] == ball[1]){ //reached the ball mult = gen_random(10)+1; player.ball_challenge = mult * dribb; player.reached = 1; } else { player.ball_challenge = -1; player.reached = -1; } } }