CAS vs. HOME - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: HP Prime (/forum-5.html) +--- Thread: CAS vs. HOME (/thread-1525.html) |
CAS vs. HOME - lrdheat - 06-03-2014 02:03 AM I was making some lotto programs and was surprised to find that RANDOM behaves differently in HOME vs. CAS. Didn't find reference to this in the onboard help. RANDINT (5,1,75) is the same in both HOME and CAS, producing 5 integers between 1 and 75 with duplicates of a number allowed. With RANDOM, however, in HOME, one gets 5 numbers between 1 and 4.99999999999 while in CAS, you get 5 integers from 1 to 75 with no duplicates! Why the different behavior? In my program, CAS.RANDOM(5,1,75) is successful as it produces 5 integers with no duplicates from 1 to 75. Thus, I could avoid using RANDINT with it's potential duplicates by using a sort list command followed by a product list command which would then produce a 0 result that could be used to determine if a duplicate had occured, and the program could repeat new sets of numbers until I had a set with no duplicates... RE: CAS vs. HOME - Joe Horn - 06-03-2014 03:18 AM (06-03-2014 02:03 AM)lrdheat Wrote: I was making some lotto programs and was surprised to find that RANDOM behaves differently in HOME vs. CAS. Didn't find reference to this in the onboard help. Many functions in CAS work differently depending on whether you type them in uppercase or lowercase letters. This is an example of that. random(a,b,c) is different from uppercase RANDOM(a,b,c) in CAS. CAS: random(a,b,c) --> reals with possible duplicates RANDOM(a,b,c) --> integers without duplicates Home: random(a,b,c) --> reals with possible duplicates RANDOM(a,b,c) --> reals with possible duplicates Please note that CAS.random(a,b,c) fails to work as expected if the CAS setting "Change apparent integers into exact integers" is unchecked (Shift CAS Settings, page 1, end of 3rd line). So if you use CAS.random(a,b,c) in Home programs, be sure that setting is checked first. Unfortunately there is no way to programmatically change that setting. |