summaryrefslogtreecommitdiff
path: root/random.c
Commit message (Collapse)AuthorAgeFilesLines
* Use C99-defined macros to classify a floating-point numberNobuyoshi Nakada2021-08-271-1/+1
|
* netbsd coroutine uses assembly instead and little build fix.David Carlier2021-08-241-1/+1
|
* rand_bytes: prefer rng->get_bytes卜部昌平2021-06-241-1/+1
| | | | | Because why not. There was no use case of rng->get_bytes before this changeset.
* Fix compilation errors in FreeBSDPeter Zhu2021-05-041-2/+2
| | | | __FreeBSD_version is defined in sys/param.h.
* Fix -Wundef warnings for patterns `#if HAVE`Benoit Daloze2021-05-041-1/+1
| | | | | | * See [Feature #17752] * Using this to detect them: git grep -P 'if\s+HAVE' | grep -Pv 'HAVE_LONG_LONG|/ChangeLog|HAVE_TYPEOF'
* Include CommonCrypto/CommonCryptoError.h for old XcodeNobuyoshi Nakada2021-03-191-0/+1
|
* Use CommonRandom if availableNobuyoshi Nakada2021-03-191-3/+18
|
* Fixed syntax error with gcc on macOSNobuyoshi Nakada2021-03-041-1/+1
| | | | | | | Security/Authorization.h defines AuthorizationExternalForm by using clang extension which allows variably modified types in a file scope. As we just need high-level accessors only, include Security/SecRandom.h instead.
* Do not allocate ractor-local storage in dfree function during GCNobuyoshi Nakada2021-02-091-1/+2
|
* OpenBSD has getentropy, but no sys/random.hKazuhiro NISHIYAMA2021-01-181-1/+3
| | | | | | | | | | | | | https://man.openbsd.org/getentropy Try to fix https://rubyci.s3.amazonaws.com/openbsd-current/ruby-master/log/20210118T023008Z.fail.html.gz ``` compiling random.c random.c:53:11: fatal error: 'sys/random.h' file not found # include <sys/random.h> ^~~~~~~~~~~~~~ 1 error generated. ```
* random generator update for Mac proposalDavid CARLIER2021-01-171-2/+18
| | | | | using getentropy for seeding, reading 256 bytes at a time to avoid the EIO errno since this is the maximum.
* Include missing AvailabilityMacros.hNobuyoshi Nakada2021-01-171-0/+4
|
* Remove possibility of using same seedsNobuyoshi Nakada2021-01-101-2/+2
|
* Random instance methodszverok2020-12-211-0/+7
|
* Deprecate Random::DEFAULTBenoit Daloze2020-12-141-0/+2
| | | | * Closes [Feature #17351].
* Remove references to Random::DEFAULT in the documentationBenoit Daloze2020-12-141-8/+6
| | | | | * Random::DEFAULT is no longer a Random instance, and referencing it is more confusing than helpful. Related to [Feature #17351]
* ractor local storage C-APIKoichi Sasada2020-12-011-11/+22
| | | | | | | | | | | | | | | | | | | | | | To manage ractor-local data for C extension, the following APIs are defined. * rb_ractor_local_storage_value_newkey * rb_ractor_local_storage_value * rb_ractor_local_storage_value_set * rb_ractor_local_storage_ptr_newkey * rb_ractor_local_storage_ptr * rb_ractor_local_storage_ptr_set At first, you need to create a key of storage by rb_ractor_local_(value|ptr)_newkey(). For ptr storage, it accepts the type of storage, how to mark and how to free with ractor's lifetime. rb_ractor_local_storage_value/set are used to access a VALUE and rb_ractor_local_storage_ptr/set are used to access a pointer. random.c uses this API.
* Use opaque struct pointer than voidNobuyoshi Nakada2020-11-271-2/+2
|
* mark default_randKoichi Sasada2020-11-271-0/+7
| | | | default_rand can points a Bignum seed, so it should be marked.
* per-ractor Random::DEFAULTKoichi Sasada2020-11-271-37/+32
| | | | | | | | | | 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]
* [DOC] Mersenne Twister isn't cryptographically secure [ci skip]Nobuyoshi Nakada2020-11-271-1/+2
|
* rb_const_set sets the class path nowNobuyoshi Nakada2020-10-091-1/+0
|
* Added `rb_random_base_init`Nobuyoshi Nakada2020-09-071-1/+8
| | | | To enclose the initialization of Random::Base part.
* Added WITH_REAL macrosNobuyoshi Nakada2020-09-071-1/+1
| | | | | | Added `WITH_REAL` versions to `RB_RANDOM_INTERFACE` macros. Also these macros including "without real" versions no longer contain the terminator (semicolon and comma).
* Added `get_real` interfaceNobuyoshi Nakada2020-09-071-0/+1
|
* Added rb_int_pair_to_realNobuyoshi Nakada2020-09-071-0/+6
|
* separate rb_random_tNobuyoshi Nakada2020-09-071-120/+230
| | | | | | | | | | | | * random.c: separate abstract rb_random_t and rb_random_mt_t for Mersenne Twister implementation. * include/ruby/random.h: the interface for extensions of Random class. * DLL imported symbol reference is not constant on Windows. * check if properly initialized.
* Random::BaseNobuyoshi Nakada2020-09-071-6/+13
| | | | | * random.c (InitVM_Random): introduce abstract super class Random::Base.
* RARRAY_AREF: convert into an inline function卜部昌平2020-08-151-0/+1
| | | | | | RARRAY_AREF has been a macro for reasons. We might not be able to change that for public APIs, but why not relax the situation internally to make it an inline function.
* rand_range: do not goto into a branch卜部昌平2020-06-291-1/+1
| | | | | I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor.
* sed -i 's|ruby/impl|ruby/internal|'卜部昌平2020-05-111-1/+1
| | | | To fix build failures.
* sed -i s|ruby/3|ruby/impl|g卜部昌平2020-05-111-1/+1
| | | | This shall fix compile errors.
* Fixed constant initializerNobuyoshi Nakada2020-05-041-1/+1
| | | | | An expression using `static const` value seems not considered as `static const` by Visual C.
* Make int-pair-to-real conversion more portableNobuyoshi Nakada2020-05-041-5/+16
| | | | And utilize more bits even if DBL_MANT_DIG > 53.
* Disable deprecation error on mingwNobuyoshi Nakada2020-04-081-0/+2
|
* Merge pull request #2991 from shyouhei/ruby.h卜部昌平2020-04-081-2/+1
| | | Split ruby.h
* Ensure seed data to be clearedNobuyoshi Nakada2020-01-101-23/+14
| | | | To prevent from leaking the seed data.
* Fill siphash salt directly with random dataNobuyoshi Nakada2020-01-101-0/+6
| | | | | Expanding less random data with MT is not needed when it succeeded.
* Renamed `init_seed` as `init_hash_salt` tooNobuyoshi Nakada2020-01-091-2/+2
|
* Renamed `seed` as `hash_salt`Nobuyoshi Nakada2020-01-091-8/+8
| | | | | The role of this is a so-called "salt" but not "seed", rename to get rid of confusion with other "seed" of PRNG.
* Also clear MT to initialize the siphash seedNobuyoshi Nakada2020-01-091-0/+1
|
* decouple internal.h headers卜部昌平2019-12-261-18/+32
| | | | | | | | | | | | | | | | | | Saves comitters' daily life by avoid #include-ing everything from internal.h to make each file do so instead. This would significantly speed up incremental builds. We take the following inclusion order in this changeset: 1. "ruby/config.h", where _GNU_SOURCE is defined (must be the very first thing among everything). 2. RUBY_EXTCONF_H if any. 3. Standard C headers, sorted alphabetically. 4. Other system headers, maybe guarded by #ifdef 5. Everything else, sorted alphabetically. Exceptions are those win32-related headers, which tend not be self- containing (headers have inclusion order dependencies).
* add several __has_something macro卜部昌平2019-12-261-1/+1
| | | | | | | With these macros implemented we can write codes just like we can assume the compiler being clang. MSC_VERSION_SINCE is defined to implement those macros, but turned out to be handy for other places. The -fdeclspec compiler flag is necessary for clang to properly handle __has_declspec().
* rand(beginless_range) raise Errno::EDOM instead of TypeErrorKazuhiro NISHIYAMA2019-12-151-2/+4
| | | | | | | | | | | | | | | | | | | | | 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) ```
* Adjusted spaces [ci skip]Nobuyoshi Nakada2019-09-271-2/+2
|
* drop-in type check for rb_define_singleton_method卜部昌平2019-08-291-5/+5
| | | | | | We can check the function pointer passed to rb_define_singleton_method like how we do so in rb_define_method. Doing so revealed many arity mismatches.
* * expand tabs.git2019-06-041-1/+1
|
* random_mt_typeNobuyoshi Nakada2019-06-041-8/+8
| | | | | * random.c: renamed random_data_type as random_mt_type, and append "MT" to `wrap_struct_name`, respecting the implementation.
* random.c: unify syscall with getrandomnobu2019-02-101-34/+14
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67046 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * expand tabs.svn2019-02-101-15/+15
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67044 b2dd03c8-39d4-4d8f-98ff-823fe69b080e