pike.git
/
src
/
builtin.cmod
version
»
Context lines:
10
20
40
80
file
none
3
pike.git/src/builtin.cmod:1:
/* -*- c -*- || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information.
-
|| $Id: builtin.cmod,v 1.
146
2004/02/
10
22
:
26
:
45
mast
Exp $
+
|| $Id: builtin.cmod,v 1.
147
2004/02/
13
23
:
09
:
25
nilsson
Exp $
*/ #include "global.h" #include "interpret.h" #include "svalue.h" #include "pike_macros.h" #include "object.h" #include "program.h" #include "array.h" #include "pike_error.h"
pike.git/src/builtin.cmod:1097:
RETURN f * (my_rand()%N/((float)N)) + f * (my_rand()%N/( ((float)N) * ((float)N) )); } /*! @decl mixed random(array|multiset xa) *! Returns a random element from @[x]. */ 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)); stack_swap(); pop_stack(); } 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"); #ifdef PIKE_NEW_MULTISETS if (multiset_indval (m)) { ptrdiff_t nodepos = multiset_get_nth (m, my_rand() % multiset_sizeof (m)); push_multiset_index (m, nodepos); push_multiset_value (m, nodepos); sub_msnode_ref (m); f_aggregate (2);