Commit Graph

59 Commits

Author SHA1 Message Date
Dominik Picheta
00f86f5591 Better error message for rand(153 .. 102) (#17031)
Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2021-02-15 08:56:17 -08:00
konsumlamm
f57774e1e7 Improve documentation for random (#17015)
* Improve documentation for random

Use runnableExamples
Minor changes

* Apply suggestions

Remove echo
Use RNG in more places

* Fix skipRandomNumbers example
2021-02-12 15:10:12 +01:00
flywind
18c24eb4d0 add system random to stdlib: std/sysrand (#16459) 2021-02-11 16:00:01 -08:00
hlaaftana
4fac8af0c9 Add initRand() with seed based on time (#16953) 2021-02-07 21:15:51 -08:00
Elliot Waite
f3d57761ab Fix broken links in docs (#16336)
* Fix broken links in docs

* Fix rand HSlice links
2020-12-14 20:13:12 +01:00
flywind
a32acc351e Revert "use generics in random (#16283)" (#16291)
This reverts commit 71e2a9e569.
2020-12-09 09:36:46 +08:00
flywind
71e2a9e569 use generics in random (#16283)
* use generics in random

* fix
2020-12-07 16:38:13 +01:00
flywind
cbc793b30b move tests to testament (#16101)
* move tests to testament

* minor

* fix random

* disable test random
2020-11-24 19:06:41 +01:00
Antonis Geralis
53d9902347 Make default state public (#15763)
* Make default state public

* Address review comments

Co-authored-by: b3liever <b3liever@yandex.com>
2020-10-29 11:14:22 +01:00
b3liever
59ba4d8c03 added normal variate function (#14725)
* added normal variate function
* change method only slightly faster
* changelog + since

Co-authored-by: b3liever <b3liever@yandex.com>
2020-06-22 20:48:33 +02:00
Miran
e7f280bd26 Remove deprecated stuff from stdlib (#14699)
* update to the latest Jester

* remove deprecated procs from some stdlib modules

* 'criterion' is not maintained anymore and relies on obsolete stuff
2020-06-17 15:25:02 +02:00
Jacek Sieka
7d6cbf290a Error -> Defect for defects (#13908)
* 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.
2020-04-28 19:56:01 +02:00
Miran
352232e62d style fix: change 'JS' to 'js' to make it consistent (#13168) 2020-01-16 14:14:03 +01:00
Miran
1551fff853 clean up deprecated stuff and unused imports in tests (#13059) 2020-01-07 09:49:08 +01:00
Judd
8b1ef8e07e allow random module to be used in standalone: (#12617)
proc randomized*() uses time releated function which is not available on
standalone, so disable this function for standalone.
2019-11-07 14:48:33 +01:00
Jjp137
93461aee34 Fix many broken links
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.
2019-10-22 17:59:12 -07:00
Miran
a5ab502f08 [backport] fix type's case in random.nim (#12445) 2019-10-17 22:13:00 +02:00
Miran
5f5ac8ce16 [backport] fix #12418, fix random.randomize on JS backend (#12432) 2019-10-15 16:29:32 +02:00
narimiran
6c994b2498 [backport] run nimpretty on numbers stuff 2019-09-30 13:58:05 +02:00
Jjp137
a906b3952b random: minor documentation updates (#11831)
Add docs for the sample procs that take in sets, and clean up a
few other minor things.
2019-08-02 02:42:18 -04:00
Miran
3bb6d1916e fix #11772, JS random seed was too large (#11820) 2019-07-25 04:53:50 -04:00
Miran
ac3449b93b [bugfix] fix #11450, random.initRand crashes in JS backend (#11522) 2019-06-17 20:46:04 +02:00
LemonBoy
7d217a71d3 Render deprecated pragmas (#8886)
* Render deprecated pragmas
* fix the expected html
* clean up the documentation regarding deprecations
* fix typo
* fix system.nim
* fix random
2019-06-03 10:15:20 +02:00
Mamy André-Ratsimbazafy
5363b8cc59 Reallow float ranges in random module 2019-05-08 13:48:03 +02:00
Jasper Jenkins
3d0190f470 Fix unexpected result of rand on a range, fixes #11015 (#11035) 2019-04-30 09:28:28 +02:00
Miran
9f94199d0c random: works for slices and enums, fixes #7698 (#10998) 2019-04-11 08:38:18 +02:00
WhiteDuke
1397ad7c54 [random] add support for sets (#10532)
* Support for sets

* Rename 'rand' to 'sample'

* Update random.nim
2019-02-25 16:45:44 +01:00
Timothee Cour
304b1dd34b randomize: added doAssert(seed!=0) to avoid invalid (non-random) behavior (#10635) 2019-02-13 23:30:14 +01:00
Jjp137
7bb94abc31 better docs: random (#10546) 2019-02-13 23:30:14 +01:00
Arne Döring
2b37bf5d5b added proc rand for typedesc (#10259) 2019-01-14 09:20:31 +01:00
c-blake
7ac1fc81fd Resolve things raised in https://github.com/nim-lang/Nim/issues/10081 ? (#10084)
* 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
2018-12-31 14:52:51 +01:00
Dominik Picheta
513a287c61 Revert sub-second randomize(). Fixes randomize for JS backend. (#10000)
Fixes #9999.
2018-12-27 11:55:21 +01:00
c-blake
e1d5356ae9 Add ability to sample elements from openArray according to a weight array (#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.)
2018-12-23 12:23:20 +00:00
Arne Döring
e012eb1001 updated tests to be executed 2018-11-23 11:58:28 +01:00
Andreas Rumpf
541debe6e1 stdlib: minor changes to avoid compiler warnings 2018-09-19 15:39:10 +02:00
Quelklef
a4c244aef0 Add checks for random.rand() (#8431) 2018-07-30 10:19:11 +02:00
Oscar Nihlgård
b34580fd5b Rename Time.nanoseconds to nanosecond (#7673)
* Rename `Time.nanoseconds` to `nanosecond`

* Fix bug with Duration comparision
2018-04-25 02:43:26 +02:00
Oscar Nihlgård
f6df2d9956 Sub second time resolution (#6978)
* 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
2018-04-13 07:36:30 +02:00
Yuriy Glukhov
1b3f640188 Fixed crash in rand (#7103) 2018-01-18 18:47:58 +01:00
GULPF
a879973081 Better times module (#6552)
* 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
2017-12-18 23:11:28 +01:00
Araq
8decf0f5ce make JS tests green again 2017-12-15 11:34:17 +01:00
Araq
196977f623 many improvements to random.nim; fixes #4726 2017-12-14 21:37:53 +01:00
Andreas Rumpf
b14cc1e3b2 fixes #6631 2017-10-30 14:45:57 +01:00
Andreas Rumpf
d52a1061b3 work in progress: new implementation for 'a[^1]' 2017-10-29 19:46:17 +01:00
Yuriy Glukhov
f3b3af5f3f Fixed randomize for 32bit target (#6167) 2017-08-01 19:53:12 +02:00
Fabian Keller
a6e0494a6f fixes #5966 2017-06-20 12:11:09 +02:00
Araq
2589d69ed2 fixes #5430 2017-02-26 00:32:07 +01:00
Vladar4
ea4397fbb0 fixed bug when the first random(max: float) call is the same value, regardless of randomize() (#5257) 2017-01-20 19:35:20 +01:00
Andreas Rumpf
767524d62a random.shuffle now takes an openArray proc 2017-01-11 06:13:27 +01:00
Benjamin Summerton
17c62bb545 Documented shuffle from random module (#5204) 2017-01-11 06:05:41 +01:00