Opened 11 years ago
Closed 10 years ago
#2686 closed Feature Request (Completed)
Random to return max value when min equals max.
Reported by: | anonymous | Owned by: | Jon |
---|---|---|---|
Milestone: | 3.3.13.10 | Component: | AutoIt |
Version: | Severity: | None | |
Keywords: | Random | Cc: |
Description
This has been rejected previously but I don't think it was fully justified. With the Random function, I suggest returning the maximum value when it is equal to the minimum value, regardless of whether you set the error flag or not. I don't personally think it should be considered an error, but maybe removing the error will break too many scripts.
Hopefully the positive outcome of such a small change would outweigh any negatives. The following code is nice and easy regatds syntax, but it currently breaks on the final iteration.
For $i = $iMin To $iMax $iRandom = Random($i, $iMax, 1) Next
Attachments (0)
Change History (9)
comment:1 Changed 11 years ago by czardas
comment:2 Changed 11 years ago by jchd18
This should file under Bugs instead of Feature request!
Any script relying on Random($n, $n, 1) with $n an integer raising an error is broken, by the mere mathematical definition of the interval [n, n], n ∈ ℕ because [n, n] = {n}, the singleton n.
I don't know how many times this must be stressed before someone engages brain.
Pick a random card out of a shuffled deck of 52 cards: OK.
Pick a random card out of the remaining 51 cards: OK.
. . .
Pick a random card out of the remaining 2 cards: OK.
Pick a random card out of the remaining 1 card: ERROR, then sing 'God save the Queen' loud?
Ridiculous.
comment:3 Changed 11 years ago by anonymous
If someone wishes to move it to bugs, then fine. It was a choice decision, so I never thought of it as a bug.
comment:4 Changed 11 years ago by czardas
You can treat it as an error and still return a value within the infinitesimal range between min and max.
comment:5 Changed 11 years ago by Melba23
Strongly supported. The argument that the return if "Min = Max" is not truly random is specious - as jchd has demonstrated.
I am less in favour of the suggestion that @error should remain set to maintain backwards compatiblity - although it could act as a flag indicating that the "Min = Max" condition exists. But the main return should certainly be the value of the 2 equal limits.
M23
comment:6 Changed 11 years ago by jchd18
Should a condition denote equality of bounds be really necessary (which I find doubtful, since its way clearer to use an If or a ternary construct to explicitely test for that), then it should be set in @extended and not in @error. That's because no error occured in this situation.
@Extended would then mean "randomlessness" — if we dare coining the term — a perfectly suitable use for @extended. This wouldn't be script breaking but script engine fixing. Anyone claiming otherwise is in a state of sin.
comment:7 Changed 11 years ago by czardas
I'm glad you guys are considering this. I also thought of getting rid of max and min. I don't see why the numbers can't appear in any order. If that's complicating matters too much, then it's easy to work around anyway.
comment:8 Changed 11 years ago by anonymous
... reluctance of developers to improve the function forces us to write the wrapper such as:
Func _random($min = 0, $max = 1, $flag = 0) If $min >= $max Then Return SetError(1, 0, $min) If @NumParams = 1 Then Return Random(0, $min, $flag) Return Random($min, $max, $flag) EndFunc ;==>_random
I think that most do similar in your scripts.
comment:9 Changed 10 years ago by Jon
- Milestone set to 3.3.13.10
- Owner set to Jon
- Resolution set to Completed
- Status changed from new to closed
Added by revision [10464] in version: 3.3.13.10
Guidelines for posting comments:
- You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
- In-depth discussions should take place on the forum.
For more information see the full version of the ticket guidelines here.
Forgot to include the author - cardas