http://www.freepascal.org/docs-html/current/rtl/system/random.html
"Random returns a random number larger or equal to 0 and strictly less than L" However random(a negative number) returns a number <= 0 and > L program r; begin randomize; writeln('Random(-10) = ',Random(-10)); end. C:\Users\Bart\LazarusProjecten>test random(-10) = -1 C:\Users\Bart\LazarusProjecten>test random(-10) = -4 Maybe my understanding of English ("strictly less than") is not correct, so I ask here before posting as a bugreport. Bart _______________________________________________ fpc-pascal maillist - [hidden email] http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal |
El 05/04/2017 a las 18:09, Bart escribió:
> http://www.freepascal.org/docs-html/current/rtl/system/random.html > > "Random returns a random number larger or equal to 0 and strictly less than L" > > However random(a negative number) returns a number <= 0 and > L > > > program r; > begin > randomize; > writeln('Random(-10) = ',Random(-10)); > end. > > C:\Users\Bart\LazarusProjecten>test > random(-10) = -1 > C:\Users\Bart\LazarusProjecten>test > random(-10) = -4 > > Maybe my understanding of English ("strictly less than") is not > correct, so I ask here before posting as a bugreport. I've never used negative values, so this is just a guess: random(+10) will output numbres 0..9 random(-10) will output numbres -9..0 so, it is equivalent to -random(10) -- Saludos Santi [hidden email] _______________________________________________ fpc-pascal maillist - [hidden email] http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal |
In reply to this post by Bart-48
Il 05/04/2017 18:09, Bart ha scritto:
http://www.freepascal.org/docs-html/current/rtl/system/random.html "Random returns a random number larger or equal to 0 and strictly less than L" However random(a negative number) returns a number <= 0 and > L program r; begin randomize; writeln('Random(-10) = ',Random(-10)); end. C:\Users\Bart\LazarusProjecten>test random(-10) = -1 C:\Users\Bart\LazarusProjecten>test random(-10) = -4 Maybe my understanding of English ("strictly less than") is not correct, so I ask here before posting as a bugreport. My scant knowledge of English leads me to believe that the sentence should be rephrased in order to cover the negative numbers case: either: Random return a random number with the same sign of L, and whose absolute value is larger or equal to zero and strictly less than the absolute value of L.or: Random return a random number in the range 0 (included) to L (excluded).Just my 2c. Giuliano _______________________________________________ fpc-pascal maillist - [hidden email] http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal |
In reply to this post by Santiago A.
On 4/5/17, Santiago A. <[hidden email]> wrote:
> random(-10) > will output numbres -9..0 That was not realy the question. The question is wether the documentation is wrong, or the implementation or neither. B.t.w. Delphi7 gives me: Random(-10) = -776108169 Random(-10) = 244426112 Random(-10) = -1774796928 Random(-10) = 1443026331 Random(-10) = -919853036 Random(-10) = -747947900 Random(-10) = -1767321924 Random(-10) = -2114448955 Random(-10) = 1499268340 Random(-10) = -1658783534 (which makes no sense at all to me...) Bart _______________________________________________ fpc-pascal maillist - [hidden email] http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal |
In reply to this post by Bart-48
Fun fact: TP's random used an unsigned parameter (word), so no ambiguity there.
Random (function) ------------------ Returns a random number. Declaration: function Random [ ( Range: Word) ]: < Same type as parameter >; Bart _______________________________________________ fpc-pascal maillist - [hidden email] http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal |
http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Random
"random returns a random number between 0 and abs(num-1)" IIUC, then Random() shoud always return a positive number. Bart _______________________________________________ fpc-pascal maillist - [hidden email] http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal |
Usualy "non-negative", not positive !
Cheers, Ched' Le 05.04.2017 à 16:55, Bart a écrit : > http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Random > > "random returns a random number between 0 and abs(num-1)" > > IIUC, then Random() shoud always return a positive number. > > Bart > _______________________________________________ > fpc-pascal maillist - [hidden email] > http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal > _______________________________________________ fpc-pascal maillist - [hidden email] http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal |
In reply to this post by Bart-48
On 05/04/17 17:55, Bart wrote:
> http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Random > > "random returns a random number between 0 and abs(num-1)" > > IIUC, then Random() shoud always return a positive number. > Mmm, I don't think so: For y := Random(num); the unsigned value of 'y' will will between 0 and abs(num-1) - inclusive, but then, the value returned keeps the sign of num; (this as per FPC implementation) I like Giuliano's definition, it is brief and beautiful: >> Random(L) returns a random number in the range 0 (included) to L (excluded). (maybe with a similarly brief and concise remark: 'regardless of the sign of L' > Bart -L. _______________________________________________ fpc-pascal maillist - [hidden email] http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal |
Free forum by Nabble | Edit this page |