pike.git / src / builtin.cmod

version» Context lines:

pike.git/src/builtin.cmod:2081:    *! @seealso    *! @[random_seed()]    */      PMOD_EXPORT   PIKEFUN int random(int i)   {    if(i <= 0) RETURN 0;   #if SIZEOF_INT_TYPE > 4    if(i >> 31) -  RETURN my_rand64() % i; +  RETURN my_rand64(i);   #endif -  RETURN my_rand() % i; +  RETURN my_rand(i);   }      /*! @decl float random(float max)    *!    *! This function returns a random number in the range @expr{0 .. @[max]-ɛ@}.    *!    *! @seealso    *! @[random_seed()]    */      PMOD_EXPORT   PIKEFUN float random(float f)   {    if(f<=0.0) RETURN 0.0;    -  RETURN (FLOAT_TYPE)ldexp((double)f * my_rand64(), -64); +  RETURN (FLOAT_TYPE)ldexp((double)f * my_rand64(0), -64);   }      /*! @decl mixed random(array|multiset x)    *! Returns a random element from @[x].    */      PMOD_EXPORT   PIKEFUN mixed random(array a)    rawtype tFunc(tArr(tSetvar(0,tMix)),tVar(0));   {    if(!a->size)    SIMPLE_BAD_ARG_ERROR("random", 1, "array with elements in it"); -  push_svalue(a->item + (my_rand() % a->size)); +  push_svalue(a->item + (my_rand(a->size)));    stack_swap();    pop_stack();   }      PMOD_EXPORT   PIKEFUN mixed random(multiset m)    rawtype tFunc(tSet(tSetvar(1,tMix)),tVar(1));   {    if(multiset_is_empty (m))    SIMPLE_BAD_ARG_ERROR("random", 1, "multiset with elements in it"); -  push_multiset_index (m, multiset_get_nth (m, my_rand() % -  multiset_sizeof (m))); +  push_multiset_index (m, multiset_get_nth (m, my_rand(multiset_sizeof (m))));    sub_msnode_ref (m);    stack_swap();    pop_stack();   }      /*! @decl array random(mapping m)    *! Returns a random index-value pair from the mapping.    */      PMOD_EXPORT   PIKEFUN array random(mapping m)   {    struct mapping_data *md=m->data;    size_t bucket, count;    struct keypair *k;       if(!m_sizeof(m))    SIMPLE_BAD_ARG_ERROR("random", 1, "mapping with elements in it");       /* Find a random, nonempty bucket */ -  bucket=my_rand() % md->hashsize; +  bucket=my_rand(md->hashsize);    while(! md->hash[bucket] )    if(++bucket > (size_t)md->hashsize)    bucket=0;       /* Count entries in bucket */    count=0;    for(k=md->hash[bucket];k;k=k->next) count++;       /* Select a random entry in this bucket */ -  count = my_rand() % count; +  count = my_rand(count);    k=md->hash[bucket];    while(count-- > 0) k=k->next;       /* Push result and return */    push_svalue(&k->ind);    push_svalue(&k->val);    f_aggregate(2);    stack_swap();    pop_stack();   }