summary refs log tree commit diff stats
path: root/lib/pure/random.nim
Commit message (Collapse)AuthorAgeFilesLines
* [backport] fix type's case in random.nim (#12445)Miran2019-10-171-12/+12
|
* [backport] fix #12418, fix `random.randomize` on JS backend (#12432)Miran2019-10-151-1/+1
|
* [backport] run nimpretty on numbers stuffnarimiran2019-09-301-17/+17
|
* random: minor documentation updates (#11831)Jjp1372019-08-021-8/+42
| | | | Add docs for the sample procs that take in sets, and clean up a few other minor things.
* fix #11772, JS random seed was too large (#11820)Miran2019-07-251-1/+1
|
* [bugfix] fix #11450, random.initRand crashes in JS backend (#11522)Miran2019-06-171-4/+4
|
* Render deprecated pragmas (#8886)LemonBoy2019-06-031-18/+12
| | | | | | | | | * Render deprecated pragmas * fix the expected html * clean up the documentation regarding deprecations * fix typo * fix system.nim * fix random
* Reallow float ranges in random moduleMamy André-Ratsimbazafy2019-05-081-4/+14
|
* Fix unexpected result of rand on a range, fixes #11015 (#11035)Jasper Jenkins2019-04-301-8/+14
|
* random: works for slices and enums, fixes #7698 (#10998)Miran2019-04-111-3/+3
|
* [random] add support for sets (#10532)WhiteDuke2019-02-251-0/+12
| | | | | | | | * Support for sets * Rename 'rand' to 'sample' * Update random.nim
* randomize: added doAssert(seed!=0) to avoid invalid (non-random) behavior ↵Timothee Cour2019-02-131-0/+1
| | | | (#10635)
* better docs: random (#10546)Jjp1372019-02-131-66/+423
|
* added proc rand for typedesc (#10259)Arne Döring2019-01-141-1/+5
|
* Resolve things raised in https://github.com/nim-lang/Nim/issues/10081 ? (#10084)c-blake2018-12-311-21/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Resolve things raised in https://github.com/nim-lang/Nim/issues/10081 ? CDF is a standard ident in all things related to random numbers/sampling, and full words "cumulativeDistributionFunction" would be silly long, in this case, IMO. We use lowercase `cdf` to make it not look like a type, remove all looping from `sample` letting callers do it. Besides just side-stepping any `sampleSize` name choice, callers may want to filter out samples anyway which this makes slightly simpler. Also add two variants of `cumsum`, value return and in-place update distinguished by the var-ness of the first argument. Add tests for `int` and `float` for both `cumsum` and the new `sample`. (The sample tests exercise the value return mode of `cumsum`.) Functionality pre-this-PR `sample(a, w)` is now the almost as simple `for i in 0..<n: sample(a, w.cumsum)`, but this new code factoring is almost surely better. The statistical tests pass, as before. * Address Araq comment in https://github.com/nim-lang/Nim/pull/10084 We can always add in some `var` version later if desired to save memory, but this change now at least firms up the `sample` interface. * Rename `cumsum` -> `cumsummed` to honor NEP1 style. Re-instate `cumsum` as the in-place transformation. Test both in `tests/stdlib/tmath.nim` and use `cumsummed` in the example code for sample since that's a simpler example. * Fix requests from https://github.com/nim-lang/Nim/pull/10084 : example in lib/pure/math.nim and comment whitespace in lib/pure/random.nim
* Revert sub-second randomize(). Fixes randomize for JS backend. (#10000)Dominik Picheta2018-12-271-2/+6
| | | Fixes #9999.
* Add ability to sample elements from openArray according to a weight array ↵c-blake2018-12-231-2/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | | (#10072) * Add the ability to sample elements from an openArray according to a parallel array of weights/unnormalized probabilities (any sort of histogram, basically). Also add a non-thread safe version for convenience. * Address Araq comments on https://github.com/nim-lang/Nim/pull/10072 * import at top of file and space after '#'. * Put in a check for non-zero total weight. * Clarify constraint on `w`. * Rename `rand(openArray[T])` to `sample(openArray[T])` to `sample`, deprecating old name and name new (openArray[T], openArray[U]) variants `sample`. * Rename caller-provided state version of rand(openArray[T]) and also clean up doc comments. * Add test for new non-uniform array sampler. 3 sd bound makes it 99% likely that it will still pass in the future if the random number generator changes. We cannot both have a tight bound to check distribution *and* loose check to ensure resilience to RNG changes. (We cannot *guarantee* resilience, anyway. There's always a small chance any test hits a legitimate random fluctuation.)
* updated tests to be executedArne Döring2018-11-231-0/+4
|
* stdlib: minor changes to avoid compiler warningsAndreas Rumpf2018-09-191-1/+1
|
* Add checks for random.rand() (#8431)Quelklef2018-07-301-2/+15
|
* Rename `Time.nanoseconds` to `nanosecond` (#7673)Oscar Nihlgård2018-04-251-1/+1
| | | | | | * Rename `Time.nanoseconds` to `nanosecond` * Fix bug with Duration comparision
* Sub second time resolution (#6978)Oscar Nihlgård2018-04-131-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Add deprecation warnings to recently deprecated procs * Fix bad usage of the times module * Introduce sub second resolution * Fix usage of C's time() * Switch to nanosecond resolution * Make Time & Duration opaque again and fix some errors * Change back to TimeInterval for shorthands * Fix JS test * Fix build error for windows * Undeprecate epochTime * Documentation and minor changes * Lots of bugfixes and doc comments * Attempt to make travis & appveyor green * Fix edge cases for dealing with the local timezone * Workaround JS backend overflow/underflow bug * Use better workaround for not knowing the size of time_t * Use all available timezones for tests * Fix indentation * Add procs for accessing the fractional part of a duration * Order time units from smallest to largest since it makes more sense * Include months and years in `TimeUnit` * Review fix
* Fixed crash in rand (#7103)Yuriy Glukhov2018-01-181-0/+5
|
* Better times module (#6552)GULPF2017-12-181-6/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * First work on better timezones * Update tests to new api. Removed tests for checking that `isDst` was included when formatting, since `isDst` no longer affects utc offset (the entire utc offset is stored directly in `utcOffset` instead). * Deprecate getLocaltime & getGmTime * Add `now()` as a shorthand for GetTIme().inZone(Local) * Add FedericoCeratto's timezone tests (#6548) * Run more tests in all timezones * Make month enum start at 1 instead of 0 * Deprecate getDayOfWeekJulian * Fix issues with gc safety * Rename TimeInfo => DateTime * Fixes #6465 * Improve isLeapYear * FIx handling negative adjTime * Cleanup: - deprecated toSeconds and fromSeconds, added fromUnix and toUnix instead (that returns int64 instead of float) - added missing doc comments - removed some unnecessary JS specific implementations * Fix misstake in JS `-` for Time * Update usage of TimeEffect * Removed unecessary use of `difftime` * JS fix for local tz * Fix subtraction of months * Fix `days` field in `toTimeInterval` * Style and docs * Fix getDayOfYear for real this time... * Fix handling of adding/subtracting time across dst transitions * Fix some bad usage of the times module in the stdlib * Revert to use proper time resoultion for seeding in random.nim * Move deprecated procs to bottom of file * Always use `epochTime` in `randomize` * Remove TimeInterval normalization * Fixes #6905 * Fix getDayOfWeek for year < 1 * Export toEpochDay/fromEpochDay and change year/month/monthday order * Add asserts for checking that the monthday is valid * Fix some remaining ambiguous references to `Time` * Fix ambiguous reference to Time
* make JS tests green againAraq2017-12-151-1/+1
|
* many improvements to random.nim; fixes #4726Araq2017-12-141-26/+97
|
* fixes #6631Andreas Rumpf2017-10-301-1/+1
|
* work in progress: new implementation for 'a[^1]'Andreas Rumpf2017-10-291-1/+1
|
* Fixed randomize for 32bit target (#6167)Yuriy Glukhov2017-08-011-2/+2
|
* fixes #5966Fabian Keller2017-06-201-1/+2
|
* fixes #5430Araq2017-02-261-1/+1
|
* fixed bug when the first random(max: float) call is the same value, ↵Vladar42017-01-201-0/+1
| | | | regardless of randomize() (#5257)
* random.shuffle now takes an openArray procAndreas Rumpf2017-01-111-2/+7
|
* Documented `shuffle` from `random` module (#5204)Benjamin Summerton2017-01-111-0/+1
|
* make random.nim work for the JS target againAraq2017-01-081-2/+4
|
* random.nim: added shuffle proc; fixes 'mod' biasAraq2017-01-081-2/+12
|
* random.nim: add a warning about crypo; refs #5047Araq2017-01-071-0/+1
|
* Fix few typosFederico Ceratto2016-10-171-2/+2
|
* Random module: fix links, improve header.Matthew Baulch2016-07-181-5/+4
|
* documentation build cleaned upAndreas Rumpf2016-05-311-3/+5
|
* make test greenAndreas Rumpf2016-05-301-20/+38
|
* moved random procs from math to its own module (breaking change)Andreas Rumpf2016-05-301-0/+23
|
* added pure Nim random stdlib moduleAndreas Rumpf2016-05-301-0/+86