Bug in documentation for Random?

8 messages
Open this post in threaded view
|

Bug in documentation for Random?

 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
Open this post in threaded view
|

Re: Bug in documentation for Random?

 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
Open this post in threaded view
|

Re: Bug in documentation for Random?

 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
Open this post in threaded view
|

Re: Bug in documentation for Random?

 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
Open this post in threaded view
|

Re: Bug in documentation for Random?

 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
Open this post in threaded view
|

Re: Bug in documentation for Random?

 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