Random Number in ATS
Post date: Jun 16, 2009 6:15:46 PM
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.