Post Reply 
CAS vs. HOME
06-03-2014, 02:03 AM
Post: #1
CAS vs. HOME
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...
Find all posts by this user
Quote this message in a reply
06-03-2014, 03:18 AM
Post: #2
RE: CAS vs. HOME
(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.

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...

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.

<0|ΙΈ|0>
-Joe-
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)