From 09846ceb72c27dfe87f0b5c8d0a6296fc09bbc36 Mon Sep 17 00:00:00 2001 From: Roland Grunberg Date: Wed, 23 Sep 2009 13:46:05 -0400 Subject: PR10632: tapset: randint() function + tests --- tapset/random.stp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 tapset/random.stp (limited to 'tapset/random.stp') diff --git a/tapset/random.stp b/tapset/random.stp new file mode 100644 index 00000000..e0a89d19 --- /dev/null +++ b/tapset/random.stp @@ -0,0 +1,18 @@ +/** @addtogroup library +* The library tapset is a collection of standard functions. +* @{ +*/ + +function randint:long(min:long, max:long) +%{ + + unsigned long difference = (unsigned long)(THIS->max - THIS->min); + + if ( THIS->min >= THIS->max || (THIS->max -THIS->min) > (1024*1024) ){ + CONTEXT->last_error = "either first argument was not strictly less than the second argument, or their difference was greater than (1024*1024)"; + } + THIS->__retvalue = THIS->min + ( _stp_random_pm_u(2147483646) % (difference + 1) ); + +%} + +/** @} */ -- cgit