mirror of
https://github.com/sass/sass.git
synced 2024-09-21 02:27:30 +00:00
Mark accepted: Random with Units Proposal (#3377)
* Mark Accepted: Random with Units Proposal * add semantic changes to 'random' in /spec * fix wording for floating point and range for ints in draft 1.1
This commit is contained in:
parent
898d716967
commit
c4bab9dc6c
9
accepted/random-with-units.changes.md
Normal file
9
accepted/random-with-units.changes.md
Normal file
@ -0,0 +1,9 @@
|
||||
## Draft 1.1
|
||||
|
||||
* Replace floating-point wording for simply "number".
|
||||
|
||||
* Update integer return value range from `[1, $limit)` to `[1, $limit]`.
|
||||
|
||||
## Draft 1
|
||||
|
||||
* Initial draft.
|
@ -1,6 +1,6 @@
|
||||
# Random With Units: Draft 1
|
||||
# Random With Units: Draft 1.1
|
||||
|
||||
*([Issue](https://github.com/sass/sass/issues/1890))*
|
||||
*([Issue](https://github.com/sass/sass/issues/1890), [Changelog](random-with-units.changes.md))*
|
||||
|
||||
This proposal modifies the behavior of the built-in [`math.random()`][random]
|
||||
function to return a number with matching units to the numeric argument it
|
||||
@ -72,14 +72,14 @@ unit-based arithmetic.
|
||||
The `math.random()` function can take an optional parameter `$limit` which
|
||||
defaults to `null`.
|
||||
|
||||
* If `$limit` is `null` then return a pseudo-random floating-point number in the
|
||||
range `[0, 1)`.
|
||||
* If `$limit` is `null` then return a pseudo-random unitless number whose value
|
||||
is in the range `[0, 1)`.
|
||||
|
||||
> Example: `math.random() => 0.1337001337`
|
||||
|
||||
* If `$limit` is an **integer** [number] greater than zero:
|
||||
|
||||
* Return a pseudo-random integer in the range `[1, $limit)` with the same
|
||||
* Return a pseudo-random integer in the range `[1, $limit]` with the same
|
||||
[units] as `$limit`.
|
||||
|
||||
> Examples:
|
@ -487,3 +487,23 @@ random($limit: null)
|
||||
```
|
||||
|
||||
This function is also available as a global function named `random()`.
|
||||
|
||||
* If `$limit` is `null` then return a pseudo-random unitless number whose value
|
||||
is in the range `[0, 1)`.
|
||||
|
||||
> Example: `math.random() => 0.1337001337`
|
||||
|
||||
* If `$limit` is an **integer** [number] greater than zero:
|
||||
|
||||
* Return a pseudo-random integer in the range `[1, $limit]` with the same
|
||||
[units] as `$limit`.
|
||||
|
||||
> Examples:
|
||||
> - `math.random(123) => 87`
|
||||
> - `math.random(123px) => 43px`
|
||||
> - `math.random(500%) => 238%`
|
||||
|
||||
* Otherwise throw an error.
|
||||
|
||||
[number]: https://sass-lang.com/documentation/values/numbers
|
||||
[units]: https://sass-lang.com/documentation/values/numbers#units
|
||||
|
Loading…
Reference in New Issue
Block a user