summary refs log tree commit diff stats
path: root/lib/pure/random.nim
Commit message (Collapse)AuthorAgeFilesLines
* Better error message for rand(153 .. 102) (#17031)Dominik Picheta2021-02-151-1/+1
| | | Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* Improve documentation for random (#17015)konsumlamm2021-02-121-185/+168
| | | | | | | | | | | | | * Improve documentation for random Use runnableExamples Minor changes * Apply suggestions Remove echo Use RNG in more places * Fix skipRandomNumbers example
* add system random to stdlib: std/sysrand (#16459)flywind2021-02-111-0/+1
|
* Add initRand() with seed based on time (#16953)hlaaftana2021-02-071-10/+35
|
* Fix broken links in docs (#16336)Elliot Waite2020-12-141-11/+17
| | | | | * Fix broken links in docs * Fix rand HSlice links
* Revert "use generics in random (#16283)" (#16291)flywind2020-12-091-15/+33
| | | This reverts commit 71e2a9e569ab3380fd057e4fc16e6d4ccd66f1f4.
* use generics in random (#16283)flywind2020-12-071-33/+15
| | | | | * use generics in random * fix
* move tests to testament (#16101)flywind2020-11-241-54/+0
| | | | | | | | | * move tests to testament * minor * fix random * disable test random
* Make default state public (#15763)Antonis Geralis2020-10-291-0/+6
| | | | | | | * Make default state public * Address review comments Co-authored-by: b3liever <b3liever@yandex.com>
* added normal variate function (#14725)b3liever2020-06-221-1/+42
| | | | | | | * added normal variate function * change method only slightly faster * changelog + since Co-authored-by: b3liever <b3liever@yandex.com>
* Remove deprecated stuff from stdlib (#14699)Miran2020-06-171-33/+1
| | | | | | | * update to the latest Jester * remove deprecated procs from some stdlib modules * 'criterion' is not maintained anymore and relies on obsolete stuff
* Error -> Defect for defects (#13908)Jacek Sieka2020-04-281-2/+2
| | | | | | | | | | | | | | * Error -> Defect for defects The distinction between Error and Defect is subjective, context-dependent and somewhat arbitrary, so when looking at an exception, it's hard to guess what it is - this happens often when looking at a `raises` list _without_ opening the corresponding definition and digging through layers of inheritance. With the help of a little consistency in naming, it's at least possible to start disentangling the two error types and the standard lib can set a good example here.
* style fix: change 'JS' to 'js' to make it consistent (#13168)Miran2020-01-161-6/+6
|
* clean up deprecated stuff and unused imports in tests (#13059)Miran2020-01-071-1/+1
|
* allow random module to be used in standalone: (#12617)Judd2019-11-071-1/+1
| | | | proc randomized*() uses time releated function which is not available on standalone, so disable this function for standalone.
* Fix many broken linksJjp1372019-10-221-1/+1
| | | | | | Note that contrary to what docgen.rst currently says, the ids have to match exactly or else most web browsers will not jump to the intended symbol.
* [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
|