aboutsummaryrefslogtreecommitdiffstats
path: root/test/ruby/test_rand.rb
Commit message (Collapse)AuthorAgeFilesLines
* Deprecate Random::DEFAULTBenoit Daloze2020-12-141-0/+2
| | | | * Closes [Feature #17351].
* per-ractor Random::DEFAULTKoichi Sasada2020-11-271-12/+0
| | | | | | | | | | Random generators are not Ractor-safe, so we need to prepare per-ractor default random genearators. This patch set `Random::DEFAULT = Randm` (not a Random instance, but the Random class) and singleton methods like `Random.rand()` use a per-ractor random generator. [Feature #17322]
* Removed useless implementation testsNobuyoshi Nakada2020-05-171-113/+14
|
* Removed PRNG implementation details from the testNobuyoshi Nakada2020-05-171-135/+79
|
* Revert "srand() should not run in tests."Koichi Sasada2020-01-291-46/+24
| | | | | | | This reverts commit 4d132fa130e16eeb4af4177cfaccc00e05e2f864. There are discussions about using srand() in tests. I'll write a ticket about it and continue to discuss.
* Revert "remove debug code."Koichi Sasada2020-01-291-0/+3
| | | | This reverts commit 65768c80beb64a14c3e918f8ed5e41e9349025d0.
* remove debug code.Koichi Sasada2020-01-281-3/+0
|
* srand() should not run in tests.Koichi Sasada2020-01-281-24/+46
| | | | | | test_rand.rb calls srand() several times, however it change global rand-sequence (and --seeds doesn't have meaning). This patch makes such tests run in other processes.
* rand(beginless_range) raise Errno::EDOM instead of TypeErrorKazuhiro NISHIYAMA2019-12-151-0/+1
| | | | | | | | | | | | | | | | | | | | | same as `rand(endless_range)` Before: ``` $ ruby -e 'rand(..1)' Traceback (most recent call last): 2: from -e:1:in `<main>' 1: from -e:1:in `rand' -e:1:in `-': nil can't be coerced into Integer (TypeError) ``` After: ``` $ ruby -e 'rand(..1)' Traceback (most recent call last): 1: from -e:1:in `<main>' -e:1:in `rand': Numerical argument out of domain (Errno::EDOM) ```
* random.c: endless range randomnobu2018-08-031-0/+1
| | | | | | | * random.c (range_values): cannot determine the domain of an endless range. [ruby-core:88261] [Bug #14958] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64167 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c: Random.bytesnobu2018-02-201-3/+8
| | | | | | | * random.c (random_s_bytes): new method Random.bytes, which is equivalent to Random::DEFAULT.bytes. [Feature #4938] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62497 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Add FrozenError as a subclass of RuntimeErrorshyouhei2017-12-121-2/+2
| | | | | | | | | | | | | | FrozenError will be used instead of RuntimeError for exceptions raised when there is an attempt to modify a frozen object. The reason for this change is to differentiate exceptions related to frozen objects from generic exceptions such as those generated by Kernel#raise without an exception class. From: Jeremy Evans <code@jeremyevans.net> Signed-off-by: Urabe Shyouhei <shyouhei@ruby-lang.org> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61131 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c: ensure initializednobu2017-07-191-0/+4
| | | | | | | * random.c (get_rnd, try_get_rnd): ensure initialized to get rid of crash in forked processes. [ruby-core:82100] [Bug #13753] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59368 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* test_rand.rb: improved assert_fork_statusnobu2017-07-191-3/+14
| | | | | | | * test/ruby/test_rand.rb (assert_fork_status): deal with errors from children. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59367 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* SecureRandom should try /dev/urandom first [Bug #9569]shyouhei2017-01-201-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | * random.c (InitVM_Random): rename Random.raw_seed to Random.urandom. A quick search seems there are no practical use of this method than securerandom.rb so I think it's OK to rename but if there are users of it, this hunk is subject to revert. * test/ruby/test_rand.rb (TestRand#test_urandom): test for it. * lib/securerandom.rb (SecureRandom.gen_random): Prefer OS- provided CSPRNG if available. Otherwise falls back to OpenSSL. Current preference is: 1. CSPRNG routine that the OS has; one of - getrandom(2), - arc4random(3), or - CryptGenRandom() 2. /dev/urandom device 3. OpenSSL's RAND_bytes(3) If none of above random number generators are available, you cannot use this module. An exception is raised that case. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57384 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* test_rand.rb: refine probability testnobu2016-08-181-3/+9
| | | | | | | * test/ruby/test_rand.rb (test_new_seed): refine probability of failure from 1/256 to 1/256**8. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55955 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* test_rand.rb: tests for seedsnobu2016-05-131-0/+14
| | | | | | | * test/ruby/test_rand.rb: tests for Random.raw_seed and Random.new_seed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54998 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c: use bytesnobu2016-05-101-0/+11
| | | | | | | * random.c (obj_random_bytes): base on bytes method instead of rand method, not to call toplevel rand method. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54968 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Add frozen_string_literal: false for all filesnaruse2015-12-161-0/+1
| | | | | | When you change this to true, you may need to add more tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53141 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * test/ruby/test_rand.rb (TestRand#test_default_seed): addkosaki2015-11-301-0/+4
| | | | | | srand case. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52817 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * random.c (Init_RandomSeed): move all Random::DEFAULTkosaki2015-11-301-0/+9
| | | | | | | | | | | | | construction bits to Init_RandomSeed2. Random::DEFAULT and Ruby internal hashes are no longer shared their seed. * random.c (Init_RandomSeed2): ditto. And, kill evil rb_obj_reveal() stuff. * random.c (init_hashseed): add MT argument. * random.c: (init_siphash): ditto. * test/ruby/test_rand.rb (TestRand#test_default_seed): new test for Random::DEFAULT::seed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52815 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * test/lib/envutil.rb: Moved from test/ruby/.akr2014-11-131-1/+0
| | | | | | | | | | | | | | * test/lib/find_executable.rb: Ditto. * test/lib/memory_status.rb: Ditto. * test/lib/test/unit.rb: require envutil. * test/: Don't require envutil in test files. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48409 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * test/ruby: get rid of warnings.usa2014-03-051-2/+3
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45273 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* test/ruby: better assertionsnobu2013-12-131-5/+5
| | | | | | * test/ruby: use better assertions instead of mere assert. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44173 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * random.c (rand_init): Make it possible to specify arbitrary arrayakr2013-11-201-1/+1
| | | | | | | | for init_genrand(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43736 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * test/ruby/test_rand.rb: fix r43224. local variable `e' isko12013-10-091-1/+1
| | | | | | | | no longer available. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43231 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* test/ruby: assert_raise_with_messagenobu2013-10-091-4/+2
| | | | | | * test/ruby: use assert_raise_with_message git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43224 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* call GC.start before fork-related tests to decrease GC cost on fork childrennaruse2013-07-111-0/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41911 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * safe.c (rb_set_safe_level, safe_setter): raise an ArgumentErrorshugo2013-06-121-12/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | when $SAFE is set to 4. $SAFE=4 is now obsolete. [ruby-core:55222] [Feature #8468] * object.c (rb_obj_untrusted, rb_obj_untrust, rb_obj_trust): Kernel#untrusted?, untrust, and trust are now deprecated. Their behavior is same as tainted?, taint, and untaint, respectively. * include/ruby/ruby.h (OBJ_UNTRUSTED, OBJ_UNTRUST): OBJ_UNTRUSTED() and OBJ_UNTRUST() are aliases of OBJ_TAINTED() and OBJ_TAINT(), respectively. * array.c, class.c, debug.c, dir.c, encoding.c, error.c, eval.c, ext/curses/curses.c, ext/dbm/dbm.c, ext/dl/cfunc.c, ext/dl/cptr.c, ext/dl/dl.c, ext/etc/etc.c, ext/fiddle/fiddle.c, ext/fiddle/pointer.c, ext/gdbm/gdbm.c, ext/readline/readline.c, ext/sdbm/init.c, ext/socket/ancdata.c, ext/socket/basicsocket.c, ext/socket/socket.c, ext/socket/udpsocket.c, ext/stringio/stringio.c, ext/syslog/syslog.c, ext/tk/tcltklib.c, ext/win32ole/win32ole.c, file.c, gc.c, hash.c, io.c, iseq.c, load.c, marshal.c, object.c, proc.c, process.c, random.c, re.c, safe.c, string.c, thread.c, transcode.c, variable.c, vm_insnhelper.c, vm_method.c, vm_trace.c: remove code for $SAFE=4. * test/dl/test_dl2.rb, test/erb/test_erb.rb, test/readline/test_readline.rb, test/readline/test_readline_history.rb, test/ruby/test_alias.rb, test/ruby/test_array.rb, test/ruby/test_dir.rb, test/ruby/test_encoding.rb, test/ruby/test_env.rb, test/ruby/test_eval.rb, test/ruby/test_exception.rb, test/ruby/test_file_exhaustive.rb, test/ruby/test_hash.rb, test/ruby/test_io.rb, test/ruby/test_method.rb, test/ruby/test_module.rb, test/ruby/test_object.rb, test/ruby/test_pack.rb, test/ruby/test_rand.rb, test/ruby/test_regexp.rb, test/ruby/test_settracefunc.rb, test/ruby/test_struct.rb, test/ruby/test_thread.rb, test/ruby/test_time.rb: remove tests for $SAFE=4. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41259 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c: increase limit for generic randnobu2013-02-241-0/+8
| | | | | | | | * random.c (rb_random_ulong_limited): limit is inclusive, but generic rand method should return a number less than it, so increase for the difference. [ruby-core:52779] [Bug #7935] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39466 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c: fix error messagenobu2013-02-221-0/+15
| | | | | | | * random.c (rb_random_ulong_limited): fix error message for negative value. [ruby-dev:47061] [Bug #7903] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39376 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c, rational.c: make marshal methods privatenobu2012-12-031-5/+5
| | | | | | | | * random.c (Init_Random), rational.c (Init_Rational): make marshal methods private. [Feature #6539] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38157 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* array.c: use rb_random_ulong_limitednobu2012-10-091-2/+3
| | | | | | | | * array.c (rb_ary_sample): use rb_random_ulong_limited, since precision of long may be larger than double. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* [Bug #6540]nobu2012-06-221-0/+8
| | | | | | | * test/ruby/test_rand.rb (TestRand#test_initialize_frozen): add missing test for [Bug #6540] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36185 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* random.c: check initialize and loadnobu2012-06-221-0/+21
| | | | | | | * random.c (random_init, random_load): cannot initialize frozen object again, nor with tainted/untrusted object. [Bug #6540] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36175 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * random.c (random_s_rand): ensure default PRNG is re-initializednobu2012-03-111-2/+31
| | | | | | after fork. patched by Eric Wong. [ruby-core:41209][Bug #5661] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34977 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * test/ruby/test_rand.rb (test_random_bytes): fold mysteriouslynobu2011-06-301-2/+6
| | | | | | long line. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32328 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * random.c (random_s_rand, Init_Random): Random.rand should behave asmrkn2011-04-241-2/+16
| | | | | | | | | | Random::DEFAULT.rand rather than Kernel#rand. * random.c (rand_range, random_rand): rand_range function extracted from random_rand function. * random.c (rb_f_rand): accept a Range argument as Random#rand [ruby-dev:43427] #4605 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31340 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * lib/test/unit.rb (assert_include): add alias.nobu2011-02-121-1/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30853 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * random.c (random_rand): get rid of overflow.nobu2010-11-201-0/+2
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29843 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * array.c (rb_ary_shuffle_bang, rb_ary_sample): add optionalnobu2010-08-231-0/+1
| | | | | | | | | argument random. [ruby-dev:41923] [EXPERIMENTAL] * random.c (rb_random_{int32,real,bytes}): fallback to normal method invocation. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29083 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * complex.c (nucomp_marshal_load): should check the argument.nobu2010-08-051-0/+7
| | | | | | | | | [ruby-core:31622] * rational.c (nurat_marshal_load): ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28869 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * random.c (Init_Random): add Random::DEFAULT.nobu2010-08-031-0/+12
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* add an assertion message.akr2010-06-051-1/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28174 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * random.c (random_rand): subtraction method of non-numeric cannobu2010-05-261-0/+3
| | | | | | | | return Float, and add the result of random to the beginning of range, not the opposite. [ruby-dev:41410] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28018 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* add a test.akr2010-04-121-0/+7
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27325 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * random.c (rand_init): ignore higher bits if all they are same asnobu2010-04-071-0/+7
| | | | | | the lower sign bit. [ruby-core:29292](2) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27255 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * random.c (random_rand): raise ArgumentError on nil, as thenobu2010-04-031-0/+1
| | | | | | | | | documentation implies. [ruby-core:29075] * random.c (rb_f_rand): mentioned the case of when max is nil. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27204 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * random.c (rb_reset_random_seed): set seed in this. [ruby-core:28655]naruse2010-03-151-0/+10
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26936 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * random.c (random_rand): fixed for edge cases of ranges.nobu2009-08-261-0/+8
| | | | | | | [ruby-dev:39166] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24674 b2dd03c8-39d4-4d8f-98ff-823fe69b080e