smlnj / legacy

This project is the old version of Standard ML of New Jersey that continues to support older systems (e.g., 32-bit machines).
BSD 3-Clause "New" or "Revised" License
25 stars 10 forks source link

`Random.randRange` when low = hi #313

Closed dlicata335 closed 1 month ago

dlicata335 commented 1 month ago

Version

110.99.4

Operating System

OS Version

Catalina

Processor

System Component

SML/NJ Library

Severity

Minor

Description

I think the behavior of Random.randRange has changed in the past year (since I last used a homework that suddenly had a bug), and is inconsistent with the documentation. The documentation says "val randRange : (int * int) -> rand -> int randRange (lo, hi) rand generates a random number in the [lo..hi]. This function will raise the Fail exception if hi < lo." This suggests one should be able to call it with low = hi (and necessarily get low=hi as the output). However,

Random.randRange (1,1) (Random.rand(1,2));

raises Div.

Transcript

No response

Expected Behavior

No response

Steps to Reproduce

Random.randRange (1,1) (Random.rand(1,2));

Additional Information

No response

Email address

dlicata@wesleyan.edu

JohnReppy commented 1 month ago

FYI the Random module was rewritten to use the Mersenne Twister algorithm in release 110.99.4 to address issue #256.

JohnReppy commented 1 month ago

There was a missing + 1 in the computation of the range. Fixed for 110.99.6.