void dice_task(bool decimal) { // check the InputB button this will start the dice rolling if (btn_state & LogicInputB) { speed = 0; timer = 0; } // roll the dice if (speed < SPEED_DONE) { if (timer < speed) { timer++; } else { speed += SPEED_INC; timer = 0; val = rand_get(6); } } // update display if (decimal) { led_select(LED_LOGIC_FNK, val); } else { led_binary(LED_COUNTER, val + 1); } }
static void IpId_Init (void) { if ( s_rand ) rand_close(s_rand); s_rand = rand_open(); if ( !s_rand ) FatalError("encode::IpId_Init: rand_open() failed.\n"); rand_get(s_rand, s_id_pool, sizeof(s_id_pool)); }
int main() { while(scanf("%d",&k)!=EOF) { for(int i=0;i<3*k;i++) scanf("%d",aa+i); for(int i=0;i<1000000;i++) { srand((unsigned)time(NULL)); rand_get(); if(check())break; } for(int i=0;i<3*k;i++) printf("%d\n",bb[i]+1); } return 0; }
static unsigned int Rand_GenRand(unsigned char *pRand, unsigned long ulRandLen) { rand_t *r; int rv; // time_t seed; r = rand_open(); if (r == NULL) return -1; if(g_ulSendlen != 0) { rv = rand_set(r,&g_Seed,g_ulSendlen); if (r == NULL) return -1; } rv = rand_get(r,pRand,ulRandLen); if (r == NULL) return -1; r = rand_close(r); memcpy(g_Seed,pRand,g_ulSendlen); return 0; }
/*lint -e525 -e438*/ int GeneratePublicKey(DH_KEY *params, unsigned char *publicValue, unsigned int pubValueLen) { rand_t *rd; int rv; time_t seed; unsigned int bytesNeeded; unsigned char seedByte[20] = {0}; R_RANDOM_STRUCT randomStruct; bytesNeeded = pubValueLen; randomStruct.bytesNeeded = bytesNeeded; memset ((POINTER)randomStruct.state, 0, sizeof (randomStruct.state)); randomStruct.outputAvailable = 0; time(&seed); rd = rand_open(); if (rd == NULL) return -1; rand_set(rd,&seed,4); if (rd == NULL) return -1; while (1) { bytesNeeded = randomStruct.bytesNeeded; if (bytesNeeded == 0) break; rand_get(rd,seedByte,16); if (rd == NULL) return -1; RandomUpdate(&randomStruct, seedByte, 16); } rd = rand_close(rd); params->priVallen = pubValueLen; rv = SetupDHAgreement(publicValue,params->privateValue,pubValueLen, params,&randomStruct); return rv; }
void clear_screen_bylines() { win_t win; int16_t i, rnd, pos; int8_t *lines = (int8_t *)malloc(g_data.ui.ydim * sizeof(int8_t)); win_init(&win, NULL); win.boxed = 0; memset(lines, 0, g_data.ui.ydim * sizeof(int8_t)); rand_open(); for (i = g_data.ui.ydim; i > 0; i--) { rnd = rand_get() % i; pos = -1; while (rnd > -1) { if (lines[++pos] == 0) rnd--; } win_setdims(&win, pos, 0, 1, g_data.ui.xdim); win_start(&win); win_draw(&win, true, true); win_stop(&win); lines[pos] = 1; usleep(min(50000, (500000 / g_data.ui.ydim))); } rand_close(); win_uninit(&win); free(lines); }
int random_generate(unsigned int seed_ext,unsigned char *buf,unsigned len) { #define SEEDBYTE_NUM 128 unsigned int seed=seed_ext; rand_t *r; int rv; unsigned pos,cnt; unsigned char seedByte[SEEDBYTE_NUM] = {0}; r = rand_open(); if (r == NULL) return -1; rv = rand_set(r,&seed,4); if (r == NULL) return -1; rv = rand_get(r,seedByte,SEEDBYTE_NUM); r = rand_close(r); if(len <= SEEDBYTE_NUM){ memcpy(buf,seedByte,len); } else{ pos = 0; while(len>0){ if(len>=SEEDBYTE_NUM){ cnt = SEEDBYTE_NUM; } else{ cnt = len; } memcpy(&buf[pos],seedByte,cnt); len -= cnt; pos += cnt; //printf("len:%d\n",len); } } #undef SEEDBYTE_NUM return 0; }
static double rand_get_double (void *vstate) { return rand_get (vstate) / 2147483648.0 ; }