int main(int argc, char **argv) { const int iter = 1000000; int i; pctrval v; v = rdtsc(); for (i = 0; i < iter; i++) arc4random(); v = rdtsc() - v; v /= iter; printf("%qd cycles\n", v); }
static uint32_t next_arc4random_uniform_value_in_range(void *user_data, uint32_t inclusive_lower_bound, uint32_t inclusive_upper_bound) { if (0 == inclusive_lower_bound && UINT32_MAX == inclusive_upper_bound) { return arc4random(); } else { uint32_t normalized_exclusive_upper_bound = inclusive_upper_bound - inclusive_lower_bound + 1; return inclusive_lower_bound + arc4random_uniform(normalized_exclusive_upper_bound); } }
uint64_t queue_generate_evpid(uint32_t msgid) { uint32_t rnd; uint64_t evpid; while ((rnd = arc4random()) == 0) ; evpid = msgid; evpid <<= 32; evpid |= rnd; return evpid; }
void arc4random_buf(void *_buf, size_t n) { size_t i; u_int32_t r = 0; char *buf = (char *)_buf; for (i = 0; i < n; i++) { if (i % 4 == 0) r = arc4random(); buf[i] = r & 0xff; r >>= 8; } i = r = 0; }
unsigned int playlist_random(void) { unsigned int ret = 0; #ifdef HAVE_ARC4RANDOM ret = arc4random(); #elif HAVE_RANDOM ret = (unsigned int)random(); #else ret = (unsigned int)rand(); #endif return (ret); }
void arc4random_buf(void *_buf, size_t n) { size_t i; u_int32_t r = 0; char *buf = (char *)_buf; for (i = 0; i < n; i++) { if (i % 4 == 0) r = arc4random(); buf[i] = r & 0xff; r >>= 8; } explicit_bzero(&r, sizeof(r)); }
u_int32_t pf_new_isn(struct pf_state *s) { MD5_CTX isn_ctx; u_int32_t md5_buffer[4]; u_int32_t new_isn; struct pf_state_host *src, *dst; /* Seed if this is the first use, reseed if requested. */ if (pf_isn_last_reseed == 0) { read_random(&pf_isn_secret, sizeof(pf_isn_secret)); pf_isn_last_reseed = ticks; } if (s->direction == PF_IN) { src = &s->ext; dst = &s->gwy; } else { src = &s->lan; dst = &s->ext; } /* Compute the md5 hash and return the ISN. */ MD5Init(&isn_ctx); MD5Update(&isn_ctx, (u_char *) &dst->port, sizeof(u_short)); MD5Update(&isn_ctx, (u_char *) &src->port, sizeof(u_short)); #ifdef INET6 if (s->af == AF_INET6) { MD5Update(&isn_ctx, (u_char *) &dst->addr, sizeof(struct in6_addr)); MD5Update(&isn_ctx, (u_char *) &src->addr, sizeof(struct in6_addr)); } else #endif { MD5Update(&isn_ctx, (u_char *) &dst->addr, sizeof(struct in_addr)); MD5Update(&isn_ctx, (u_char *) &src->addr, sizeof(struct in_addr)); } MD5Update(&isn_ctx, (u_char *) &pf_isn_secret, sizeof(pf_isn_secret)); MD5Final((u_char *) &md5_buffer, &isn_ctx); new_isn = (tcp_seq) md5_buffer[0]; pf_isn_offset += ISN_STATIC_INCREMENT + (arc4random() & ISN_RANDOM_INCREMENT); new_isn += pf_isn_offset; return (new_isn); }
static const char *pbkdf2v2_make_salt(void) { char salt[PBKDF2_SALTLEN + 1]; static char result[PASSLEN]; memset(salt, 0x00, sizeof salt); memset(result, 0x00, sizeof result); for (int i = 0; i < PBKDF2_SALTLEN; i++) salt[i] = salt_chars[arc4random() % sizeof salt_chars]; (void) snprintf(result, sizeof result, PBKDF2_F_SALT, pbkdf2v2_digest, pbkdf2v2_rounds, salt); return result; }
/* init_des_cipher: initialize DES */ void init_des_cipher(void) { #ifdef DES int i; des_ct = des_n = 0; /* initialize the initialization vector */ MEMZERO(ivec, 8); /* initialize the padding vector */ for (i = 0; i < 8; i++) pvec[i] = (char) (arc4random() % 256); #endif }
//初始化矩阵数据 void RootEngine::initStars() { dataSource = CCArray::create(); blocksInSameColor = CCArray::create(); checkedBlocks = CCArray::create(); allNodes = CCArray::create(); allNodes->retain(); dataSource->retain(); blocksInSameColor->retain(); checkedBlocks->retain(); Size contentSize = containerView->getContentSize(); perWidth = contentSize.width/lineCount; perHeight = perWidth; CCArray* nameArray = CCArray::create(); for (int i = 0; i<typeCount; i++) { __String* s = __String::createWithFormat("img_star_%02d.png",i); nameArray->addObject(s); } for (int i = 0; i<lineCount; i++) { CCArray* lineArray = CCArray::create(); dataSource->addObject(lineArray); for (int j = 0; j<rowCount; j++) { int type = arc4random()%typeCount; StarModel* model = new StarModel(); model->type = type; model->line = i; model->row = j; lineArray->addObject(model); __String* file = (__String*)nameArray->objectAtIndex(model->type); Sprite* bSprite = Sprite::create(file->getCString()); bSprite->setPosition(Point((i+ 0.5)*this->perHeight, (j+0.5)*this->perWidth)); bSprite->setScale(CommonUtil::getScaleForTargetWithImage(perWidth, bSprite)); containerView->addChild(bSprite); StarNode* node = new StarNode(); node->sprite = bSprite; node->model = model; node->targetCenter = bSprite->getPosition(); model->node = node; allNodes->addObject(node); } } }
Server::Server(const char *N_str, const char *g_str, const char *k_str, const char *_I, const char *_P) { N = NULL; g = NULL; k = NULL; v = NULL; hmac = NULL; SHA256_CTX sha_ctx; if (N_str) BN_hex2bn(&N, N_str); if (g_str) BN_hex2bn(&g, g_str); if (k_str) BN_hex2bn(&k, k_str); if (_I) { I = new char[strlen(_I)+1]; strcpy(I, _I); } if (_P) { P = new char[strlen(_P)+1]; strcpy(P, _P); } // S // Generate salt as random integer // Generate string xH=SHA256(salt|password) // Convert xH to integer x somehow (put 0x on hexdigest) // Generate v=g**x % N // Save everything but x, xH salt = arc4random(); unsigned char xH[SHA256_HASH_LEN]; SHA256_Init(&sha_ctx); SHA256_Update(&sha_ctx, &salt, sizeof salt); SHA256_Update(&sha_ctx, P, strlen(P)); SHA256_Final(xH, &sha_ctx); BIGNUM *x = BN_new(); BN_bin2bn(xH, SHA256_HASH_LEN, x); v = BN_new(); BN_CTX *ctx = BN_CTX_new(); BN_mod_exp(v, g, x, N, ctx); if (x) BN_free(x); if (ctx) BN_CTX_free(ctx); }
int main(int argc, const char * argv[]) { //first, we create the linked list header node *root = malloc(sizeof(node)); node *end = malloc(sizeof(node)); root->next = end; end->prev = root; end->next = NULL; node *current_node = root; int index; int list_size = 100; //then make linked list of 350 //this will be our usable coefficient buffer for (index = 0; index<list_size; index++){ int random_number = arc4random() % 150; random_number = (random_number%2)? random_number*-1: random_number; node *new_node = malloc(sizeof(node)); new_node->coeff_struct.coefficient = random_number; add_to_linked_list(new_node, current_node); current_node = current_node->next; } printf("\n"); printf("loop coefficients are: "); //print_linked_list(root); printf("\n"); char *message = "Hello";/* that whirl me I know not whither\nYour schemes, politics, fail, lines give way, substances mock and elude me,\nOnly the theme I sing, the great and strong-possess'd soul, eludes not,\nOne's-self must never give way--that is the final substance--that\nout of all is sure,\nOut of politics, triumphs, battles, life, what at last finally remains?\nWhen shows break up what but One's-Self is sure?";*/ embedMessageIntoCoefficients(message, root, list_size); printf("\n\nour stego coefficients: \n"); print_linked_list(root); printf("\n"); int message_size = (int)strlen(message)*8; //getting size of message in bits char *extractedMessage = malloc(sizeof(char) *message_size); extractMessageFromCoefficients(root, list_size, message_size, extractedMessage); return 0; }
void InfoSlide2:: ExplodeAnimation(){ CCAnimation* explode = createArray((char*)"explodingSymbol", 18); for (int i= 0 ; i< allSymbols->count(); i++) { float delay = (float) ((arc4random() % 5) / 10.0); CCAnimate* ani = CCAnimate::create(explode); SyntaxSymbol* temp = (SyntaxSymbol*)allSymbols->objectAtIndex(i); temp->runAction(CCSequence::create(CCDelayTime::create(delay) ,ani,CCFadeTo::create(0.00001, 0.0f),NULL)); } CCAnimate* ani = CCAnimate::create(explode); symbolToMakeExplosive->runAction(CCSequence::create(ani,CCFadeTo::create(0.0000001, 0.0f),NULL)); }
int RAND_bytes(unsigned char *buf, int num) { uint32_t r; size_t cc; int i; if (buf == NULL || num < 0) { return 0; } for (i = 0 ; i < num ; i += sizeof(r)) { r = arc4random(); cc = MIN(sizeof(r), (size_t)(num - i)); (void) memcpy(&buf[i], &r, cc); } return 1; }
static void privsep_preauth_child(void) { u_int32_t rand[256]; gid_t gidset[2]; struct passwd *pw; int i; /* Enable challenge-response authentication for privilege separation */ privsep_challenge_enable(); for (i = 0; i < 256; i++) rand[i] = arc4random(); RAND_seed(rand, sizeof(rand)); /* Demote the private keys to public keys. */ demote_sensitive_data(); if ((pw = getpwnam(SSH_PRIVSEP_USER)) == NULL) fatal("Privilege separation user %s does not exist", SSH_PRIVSEP_USER); memset(pw->pw_passwd, 0, strlen(pw->pw_passwd)); endpwent(); /* Change our root directory*/ if (chroot(_PATH_PRIVSEP_CHROOT_DIR) == -1) fatal("chroot(\"%s\"): %s", _PATH_PRIVSEP_CHROOT_DIR, strerror(errno)); if (chdir("/") == -1) fatal("chdir(\"/\"): %s", strerror(errno)); /* Drop our privileges */ debug3("privsep user:group %u:%u", (u_int)pw->pw_uid, (u_int)pw->pw_gid); #if 0 /* XXX not ready, to heavy after chroot */ do_setusercontext(pw); #else gidset[0] = pw->pw_gid; if (setgid(pw->pw_gid) < 0) fatal("setgid failed for %u", pw->pw_gid ); if (setgroups(1, gidset) < 0) fatal("setgroups: %.100s", strerror(errno)); permanently_set_uid(pw); #endif }
/********** * This function cannot be compressed in anyway * That means that if it is included multiple times it must * force the end binary size to grow **********/ int unoptimizable(int y) { long long x = arc4random()+ y*y*y; if (x * x >= 1282416807LL) { x = 0 % x;} if (x * x >= 198491622650073LL) { x = 1 % x;} if (x * x >= 147021144108930LL) { x = 2 % x;} if (x * x >= 114578101027544LL) { x = 3 % x;} if (x * x >= 1200721458777923LL) { x = 4 % x;} if (x * x >= 111154823564440LL) { x = 5 % x;} if (x * x >= 17421784484492LL) { x = 6 % x;} if (x * x >= 111375114807987LL) { x = 7 % x;} if (x * x >= 11651441282327LL) { x = 8 % x;} if (x * x >= 11435823378840LL) { x = 9 % x;} if (x * x >= 114748896544303LL) { x = 10 % x;} if (x * x >= 1199801264817709LL) { x = 11 % x;} if (x * x >= 1113151817129560LL) { x = 12 % x;} if (x * x >= 114042197493099LL) { x = 13 % x;} if (x * x >= 115057893351816LL) { x = 14 % x;} if (x * x >= 1163681954899097LL) { x = 15 % x;} if (x * x >= 11019563613512LL) { x = 16 % x;} if (x * x >= 170481580723810LL) { x = 17 % x;} if (x * x >= 1162431358580979LL) { x = 18 % x;} if (x * x >= 178452128236579LL) { x = 19 % x;} return x; }
int tss_populate_random(plist_t tssreq, int is64bit, uint64_t ecid){ char nonce[noncelen+1]; char sep_nonce[noncelen+1]; int n=0; if (!ecid) for (int i=0; i<16; i++) ecid += (arc4random() % 10) * pow(10, n++); getRandNum(nonce, noncelen, 256); getRandNum(sep_nonce, noncelen, 256); nonce[noncelen] = sep_nonce[noncelen] = 0; debug("[TSSR] ecid=%llu\n",ecid); debug("[TSSR] nonce=%s\n",nonce); debug("[TSSR] sepnonce=%s\n",sep_nonce); return tss_populate_devicevals(tssreq, ecid, nonce, noncelen, sep_nonce, noncelen, is64bit); }
struct fusebuf * fb_setup(size_t len, ino_t ino, int op, struct proc *p) { struct fusebuf *fbuf; fbuf = pool_get(&fusefs_fbuf_pool, PR_WAITOK | PR_ZERO); fbuf->fb_len = len; fbuf->fb_err = 0; fbuf->fb_uuid = arc4random(); fbuf->fb_type = op; fbuf->fb_ino = ino; fbuf->fb_resid = -1; DPRINTF("create unique %lu\n", fbuf->fb_uuid); return (fbuf); }
void Curl_darwinssl_random(struct SessionHandle *data, unsigned char *entropy, size_t length) { /* arc4random_buf() isn't available on cats older than Lion, so let's do this manually for the benefit of the older cats. */ size_t i; u_int32_t random_number = 0; for(i = 0 ; i < length ; i++) { if(i % sizeof(u_int32_t) == 0) random_number = arc4random(); entropy[i] = random_number & 0xFF; random_number >>= 8; } i = random_number = 0; (void)data; }
/** * initialize L2TP daemon instance * <p> * {@link _l2tpd#bind_sin} will return with .sin_family = AF_INET, * .sin_port = 1701 and .sin_len = "appropriate value" * </p> */ int l2tpd_init(l2tpd *_this) { int i, off; u_int id; L2TPD_ASSERT(_this != NULL); memset(_this, 0, sizeof(l2tpd)); slist_init(&_this->listener); slist_init(&_this->free_session_id_list); _this->id = l2tpd_id_seq++; if ((_this->ctrl_map = hash_create(short_cmp, short_hash, L2TPD_TUNNEL_HASH_SIZ)) == NULL) { log_printf(LOG_ERR, "hash_create() failed in %s(): %m", __func__); return 1; } if (slist_add(&_this->free_session_id_list, (void *)L2TP_SESSION_ID_SHUFFLE_MARK) == NULL) { l2tpd_log(_this, LOG_ERR, "slist_add() failed on %s(): %m", __func__); return 1; } off = arc4random() & L2TP_SESSION_ID_MASK; for (i = 0; i < L2TP_NCALL; i++) { id = (i + off) & L2TP_SESSION_ID_MASK; if (id == 0) id = (off - 1) & L2TP_SESSION_ID_MASK; if (slist_add(&_this->free_session_id_list, (void *)(uintptr_t)id) == NULL) { l2tpd_log(_this, LOG_ERR, "slist_add() failed on %s(): %m", __func__); return 1; } } _this->purge_ipsec_sa = 1; _this->state = L2TPD_STATE_INIT; return 0; }
ino_t cgialloc(struct uufsd *disk) { struct ufs2_dinode *dp2; u_int8_t *inosused; struct cg *cgp; struct fs *fs; ino_t ino; int i; fs = &disk->d_fs; cgp = &disk->d_cg; inosused = cg_inosused(cgp); for (ino = 0; ino < fs->fs_ipg; ino++) if (isclr(inosused, ino)) goto gotit; return (0); gotit: if (fs->fs_magic == FS_UFS2_MAGIC && ino + INOPB(fs) > cgp->cg_initediblk && cgp->cg_initediblk < cgp->cg_niblk) { char block[MAXBSIZE]; bzero(block, (int)fs->fs_bsize); dp2 = (struct ufs2_dinode *)█ for (i = 0; i < INOPB(fs); i++) { dp2->di_gen = arc4random() / 2 + 1; dp2++; } if (bwrite(disk, ino_to_fsba(fs, cgp->cg_cgx * fs->fs_ipg + cgp->cg_initediblk), block, fs->fs_bsize)) return (0); cgp->cg_initediblk += INOPB(fs); } setbit(inosused, ino); cgp->cg_irotor = ino; cgp->cg_cs.cs_nifree--; fs->fs_cstotal.cs_nifree--; fs->fs_cs(fs, cgp->cg_cgx).cs_nifree--; fs->fs_fmod = 1; return (ino + (cgp->cg_cgx * fs->fs_ipg)); }
void CInkyGhost::changeNewDirection() { switch (arc4random() % 4) { case 0: _direction = LEFT; break; case 1: _direction = RIGHT; break; case 2: _direction = UP; break; case 3: _direction = DOWN; break; default: break; } }
pcp_key_t * pcpkey_new () { byte *mp = ucmalloc(LEDPUB); byte *ms = ucmalloc(LEDSEC); byte *sp = ucmalloc(LEDPUB); byte *ss = ucmalloc(LEDSEC); byte *cp = ucmalloc(LBOXPUB); byte *cs = ucmalloc(LBOXSEC); /* generate key material */ pcp_keypairs(ms, mp, cs, cp, ss, sp); /* fill in our struct */ pcp_key_t *key = urmalloc(sizeof(pcp_key_t)); memcpy (key->masterpub, mp, LEDPUB); memcpy (key->mastersecret, ms, LEDSEC); memcpy (key->pub, cp, LBOXPUB); memcpy (key->secret, cs, LBOXSEC); memcpy (key->edpub, sp, LEDPUB); memcpy (key->edsecret, ss, LEDSEC); char *id = pcp_getkeyid(key); memcpy (key->id, id, 17); free(id); key->ctime = (long)time(0); key->version = PCP_KEY_VERSION; key->serial = arc4random(); key->type = PCP_KEY_TYPE_SECRET; key->owner[0] = '\0'; key->mail[0] = '\0'; /* clean up */ ucfree(ms, LEDSEC); ucfree(ss, LEDSEC); ucfree(mp, LEDPUB); ucfree(sp, LEDPUB); ucfree(cs, LBOXSEC); ucfree(cp, LBOXPUB); return key; }
unsigned long prng_uint32(void) { return #if defined(OS_MACOSX) // arc4random() returns a 32-bit random number: arc4random(); #elif defined(OS_LINUX) // random() returns a 31-bit random number: (((unsigned long)(random() & 0xFFFF)) << 16) | (((unsigned long)(random() & 0xFFFF)) << 0); #elif defined(OS_WINDOWS_MOBILE) Random(); #elif defined(OS_WINDOWS) // rand() returns a 15-bit random number: (((unsigned long) (rand() & 0xFF)) << 24) | (((unsigned long) (rand() & 0xFFF)) << 12) | (((unsigned long) (rand() & 0xFFF)) << 0); #endif }
static double calc_dice_simple(double lhs, double rhs) { double i; double out = 0.0; if (lhs <= 0.0) lhs = 1.0; if (rhs <= 0.0) rhs = 1.0; for (i = 0; i < lhs; i++) { int sides = floorl(rhs); out += 1.0 + (arc4random() % sides); } return out; }
int main(int argc, const char * argv[]) { //这部分是增加随机数的。 printf("请输入一个数组的大小\n"); int number; scanf("%d",&number); int array[number]; for (int i = 0; i <number; i ++){ int numberARC = arc4random()%100; array[i] = numberARC; printf("%d ",array[i]); } printf("\n"); /* 首先我们确定了 i 它总共是比4轮 i (轮数) 1 2 3 4 接下来我们确定 j 表示的是每一轮比较的次数 j(比较次数) 4次 3次 2次 1次 因为数组是从0开始的,所以我们i和j也从0开始方便一点。 i 0 1 2 3 j 4-i 4-i 4-i 4-i */ //这部分是正常逻辑 for (int i = 0; i <number - 1; i++) { for (int j = 0; j < number - i -1; j ++) { if (array[j]>array[j+1]) { int temp = array[j+1]; array[j+1] = array[j]; array[j] = temp; } } } for (int i = 0; i <number; i++) { printf("%d ",array[i]); } printf("\n"); return 0; }
void* OSAllocator::reserveAndCommit(size_t bytes, Usage usage, bool writable, bool executable) { // All POSIX reservations start out logically committed. int protection = PROT_READ; if (writable) protection |= PROT_WRITE; if (executable) protection |= PROT_EXEC; int flags = MAP_PRIVATE | MAP_ANON; #if WTF_OS_DARWIN && !defined(BUILDING_ON_TIGER) int fd = usage; #else int fd = -1; #endif void* result = 0; #if (WTF_OS_DARWIN && WTF_CPU_X86_64) if (executable) { // Cook up an address to allocate at, using the following recipe: // 17 bits of zero, stay in userspace kids. // 26 bits of randomness for ASLR. // 21 bits of zero, at least stay aligned within one level of the pagetables. // // But! - as a temporary workaround for some plugin problems (rdar://problem/6812854), // for now instead of 2^26 bits of ASLR lets stick with 25 bits of randomization plus // 2^24, which should put up somewhere in the middle of userspace (in the address range // 0x200000000000 .. 0x5fffffffffff). intptr_t randomLocation = 0; randomLocation = arc4random() & ((1 << 25) - 1); randomLocation += (1 << 24); randomLocation <<= 21; result = reinterpret_cast<void*>(randomLocation); } #endif result = mmap(result, bytes, protection, flags, fd, 0); if (result == MAP_FAILED) CRASH(); return result; }
/* * Reuse, or allocate (and program the page pods for) a new DDP buffer. The * "pages" array is handed over to this function and should not be used in any * way by the caller after that. */ static int select_ddp_buffer(struct adapter *sc, struct toepcb *toep, vm_page_t *pages, int npages, int db_off, int db_len) { struct ddp_buffer *db; struct tom_data *td = sc->tom_softc; int i, empty_slot = -1; /* Try to reuse */ for (i = 0; i < nitems(toep->db); i++) { if (bufcmp(toep->db[i], pages, npages, db_off, db_len) == 0) { free(pages, M_CXGBE); return (i); /* pages still held */ } else if (toep->db[i] == NULL && empty_slot < 0) empty_slot = i; } /* Allocate new buffer, write its page pods. */ db = alloc_ddp_buffer(td, pages, npages, db_off, db_len); if (db == NULL) { vm_page_unhold_pages(pages, npages); free(pages, M_CXGBE); return (-1); } if (write_page_pods(sc, toep, db) != 0) { vm_page_unhold_pages(pages, npages); free_ddp_buffer(td, db); return (-1); } i = empty_slot; if (i < 0) { i = arc4random() % nitems(toep->db); free_ddp_buffer(td, toep->db[i]); } toep->db[i] = db; CTR5(KTR_CXGBE, "%s: tid %d, DDP buffer[%d] = %p (tag 0x%x)", __func__, toep->tid, i, db, db->tag); return (i); }
void atheme_init(char *execname, char *log_p) { me.execname = execname; me.kline_id = 0; me.start = time(NULL); CURRTIME = me.start; srand(arc4random()); /* set signal handlers */ init_signal_handlers(); /* initialize strshare */ strshare_init(); /* open log */ log_path = log_p; log_open(); mowgli_log_set_cb(process_mowgli_log); }
static int vtbe_get_hwaddr(struct vtbe_softc *sc, uint8_t *hwaddr) { int rnd; /* * Generate MAC address, use 'bsd' + random 24 low-order bits. */ rnd = arc4random() & 0x00ffffff; hwaddr[0] = 'b'; hwaddr[1] = 's'; hwaddr[2] = 'd'; hwaddr[3] = rnd >> 16; hwaddr[4] = rnd >> 8; hwaddr[5] = rnd >> 0; return (0); }