Changeset 331 for EcnlProtoTool/trunk/mruby-1.3.0/mrbgems/mruby-random
- Timestamp:
- Jan 21, 2018, 12:10:09 AM (6 years ago)
- Location:
- EcnlProtoTool/trunk/mruby-1.3.0
- Files:
-
- 5 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
EcnlProtoTool/trunk/mruby-1.3.0/mrbgems/mruby-random/src/mt19937ar.c
r321 r331 2 2 ** mt19937ar.c - MT Random functions 3 3 ** 4 ** See Copyright Notice in mruby.h 4 ** Copyright (C) 1997 - 2016, Makoto Matsumoto and Takuji Nishimura, 5 ** All rights reserved. 6 ** 7 ** Permission is hereby granted, free of charge, to any person obtaining 8 ** a copy of this software and associated documentation files (the 9 ** "Software"), to deal in the Software without restriction, including 10 ** without limitation the rights to use, copy, modify, merge, publish, 11 ** distribute, sublicense, and/or sell copies of the Software, and to 12 ** permit persons to whom the Software is furnished to do so, subject to 13 ** the following conditions: 14 ** 15 ** The above copyright notice and this permission notice shall be 16 ** included in all copies or substantial portions of the Software. 17 ** 18 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 ** 26 ** [ MIT license: http://www.opensource.org/licenses/mit-license.php ] 27 ** 28 ** Any feedback is very welcome. 29 ** http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html 30 ** email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space) 31 ** 32 ** This version is modified by mruby developers. If you see any problem, 33 ** contact us first at https://github.com/mruby/mruby/issues 5 34 */ 6 35 7 #include "mruby.h"36 #include <mruby.h> 8 37 #include "mt19937ar.h" 9 38 -
EcnlProtoTool/trunk/mruby-1.3.0/mrbgems/mruby-random/src/mt19937ar.h
r321 r331 2 2 ** mt19937ar.h - MT Random functions 3 3 ** 4 ** See Copyright Notice in mruby.h 4 ** Copyright (C) 1997 - 2016, Makoto Matsumoto and Takuji Nishimura, 5 ** All rights reserved. 6 ** 7 ** Permission is hereby granted, free of charge, to any person obtaining 8 ** a copy of this software and associated documentation files (the 9 ** "Software"), to deal in the Software without restriction, including 10 ** without limitation the rights to use, copy, modify, merge, publish, 11 ** distribute, sublicense, and/or sell copies of the Software, and to 12 ** permit persons to whom the Software is furnished to do so, subject to 13 ** the following conditions: 14 ** 15 ** The above copyright notice and this permission notice shall be 16 ** included in all copies or substantial portions of the Software. 17 ** 18 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 ** 26 ** [ MIT license: http://www.opensource.org/licenses/mit-license.php ] 27 ** 28 ** Any feedback is very welcome. 29 ** http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html 30 ** email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space) 31 ** 32 ** This version is modified by mruby developers. If you see any problem, 33 ** contact us first at https://github.com/mruby/mruby/issues 5 34 */ 6 35 -
EcnlProtoTool/trunk/mruby-1.3.0/mrbgems/mruby-random/src/random.c
r321 r331 5 5 */ 6 6 7 #include "mruby.h"8 #include "mruby/variable.h"9 #include "mruby/class.h"10 #include "mruby/data.h"11 #include "mruby/array.h"7 #include <mruby.h> 8 #include <mruby/variable.h> 9 #include <mruby/class.h> 10 #include <mruby/data.h> 11 #include <mruby/array.h> 12 12 #include "mt19937ar.h" 13 13 … … 80 80 81 81 if (!mrb_nil_p(arg)) { 82 if (!mrb_fixnum_p(arg)) { 82 arg = mrb_check_convert_type(mrb, arg, MRB_TT_FIXNUM, "Fixnum", "to_int"); 83 if (mrb_nil_p(arg)) { 83 84 mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid argument type"); 84 85 } 85 arg = mrb_check_convert_type(mrb, arg, MRB_TT_FIXNUM, "Fixnum", "to_int");86 86 if (mrb_fixnum(arg) < 0) { 87 87 arg = mrb_fixnum_value(0 - mrb_fixnum(arg)); … … 125 125 mt_state *t; 126 126 127 seed = get_opt(mrb); 128 127 129 /* avoid memory leaks */ 128 130 t = (mt_state*)DATA_PTR(self); … … 135 137 t->mti = N + 1; 136 138 137 seed = get_opt(mrb);138 139 seed = mrb_random_mt_srand(mrb, t, seed); 139 140 if (mrb_nil_p(seed)) { … … 267 268 mrb_bool given; 268 269 mt_state *random = NULL; 269 mrb_int len = RARRAY_LEN(ary);270 mrb_int len; 270 271 271 272 mrb_get_args(mrb, "|i?d", &n, &given, &random, &mt_state_type); … … 275 276 mrb_random_rand_seed(mrb, random); 276 277 mt_rand(random); 278 len = RARRAY_LEN(ary); 277 279 if (!given) { /* pick one element */ 278 280 switch (len) { -
EcnlProtoTool/trunk/mruby-1.3.0/mrbgems/mruby-random/src/random.h
r321 r331 5 5 */ 6 6 7 #ifndef RANDOM_H8 #define RANDOM_H7 #ifndef MRUBY_RANDOM_H 8 #define MRUBY_RANDOM_H 9 9 10 10 void mrb_mruby_random_gem_init(mrb_state *mrb); -
EcnlProtoTool/trunk/mruby-1.3.0/mrbgems/mruby-random/test/random.rb
r321 r331 75 75 ary1 != [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] and 10.times { |x| ary1.include? x } and ary1 == ary2 76 76 end 77 78 assert('Array#sample checks input length after reading arguments') do 79 $ary = [1, 2, 3] 80 class ArrayChange 81 def to_i 82 $ary << 4 83 4 84 end 85 end 86 87 assert_equal [1, 2, 3, 4], $ary.sample(ArrayChange.new).sort 88 end
Note:
See TracChangeset
for help on using the changeset viewer.