Teaching‎ > ‎CS320 Summer I 2009 TF‎ > ‎

Random Number in ATS

posted Jun 16, 2009, 11:15 AM by Site Admin Role   [ updated Jun 16, 2009, 11:27 AM ]

If you use the lrand48() function in "libc/SATS/random.sats", then you probably need a way to convert from lint (long int) to int. There is a primitive function called atspre_int_of_lint defined in "prelude/CATS/integer.cats" but there is no function type declaration in the corresponding "prelude/SATS/integer.sats". In order to use it in your code, add this to your .dats file:

staload "libc/SATS/random.sats"
extern fun int_of_lint (li: lint):<> int = "atspre_int_of_lint"

And you can call the function as int_of_lint. Example code is attached below.

You can also manipulate lint in ATS directly (arithmetics, comparison, etc.). You can write lint constants by suffixing a number with 'l', e.g. 0l for zero, and 1l for one.

ċ
linttest.dats
(0k)
Site Admin Role,
Jun 16, 2009, 11:23 AM
Comments