2015-07-22 20:32:54 +02:00
# ifndef INCLUDE_RANDOM_H
# define INCLUDE_RANDOM_H
2015-08-04 17:48:36 +02:00
# print "[include <random.h>]\n"
2012-11-26 16:26:15 +01:00
2015-07-22 20:32:54 +02:00
# ifndef INCLUDE_KOLIBRI_H
# include "../lib/kolibri.h"
# endif
2012-11-26 16:26:15 +01:00
2015-07-16 03:44:30 +02:00
# define MASK_RAND 123456789
# define IQ_RAND 12773
# define IA_RAND 16807
# define IR_RAND 2836
# define IM_RAND 2147483647
# define AM_RAND (1. / 2147483647)
2012-11-26 16:26:15 +01:00
inline fastcall int random ( ECX )
// get pseudo-random number - <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD>
{
$ push ebx
$ rdtsc // eax & edx
$ xor eax , edx
$ not eax
2015-07-12 01:45:19 +02:00
EBX = __generator ;
2012-11-26 16:26:15 +01:00
$ ror ebx , 3
$ xor ebx , 0xdeadbeef
EBX + = EAX ;
2015-07-12 01:45:19 +02:00
__generator = EBX ;
2012-11-26 16:26:15 +01:00
EAX + = EBX ;
EAX = EAX % ECX ;
$ pop ebx
}
2015-07-20 01:09:56 +02:00
inline long unirand0 ( void )
2015-07-16 03:44:30 +02:00
{
long k , ans , tmp , save ;
save = __generator ;
__generator ^ = MASK_RAND ; /* avoid __generator==0 */
k = __generator / IQ_RAND ;
tmp = __generator - k * IQ_RAND ;
__generator * = IA_RAND * tmp ;
__generator - = IR_RAND * k ;
if ( __generator < 0 ) __generator + = IM_RAND ;
if ( save = = __generator ) return unirand0 ( ) ;
ans = __generator ;
__generator ^ = MASK_RAND ; /* restore unmasked dummy */
return ans ;
}
: long RAND_A , RAND_C , RAND_TMP ;
2015-07-20 01:09:56 +02:00
inline long rand ( signed long x1 , x2 )
2015-07-16 03:44:30 +02:00
{
long tmp , xx ;
RAND_A = __generator ;
__generator = RAND_A * __generator + RAND_C ;
RAND_C = __generator ^ RAND_A ;
RAND_C > > = 1 ;
RAND_A < < = 1 ;
__generator ^ = RAND_A ;
xx = x2 ;
if ( x1 < 0 ) xx + = - x1 ;
tmp = __generator % xx ;
if ( tmp < 0 ) tmp = - tmp ;
tmp + = x1 ;
return tmp ;
}
2012-11-26 16:26:15 +01:00
inline fastcall randomize ( )
2015-07-12 01:45:19 +02:00
// initialize random number __generator - <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD>
2012-11-26 16:26:15 +01:00
{
asm
{
mov eax , 3
int 0x40
ror eax , 16
}
2015-07-16 03:44:30 +02:00
//if(EAX == __generator)return randomize();
2015-07-12 01:45:19 +02:00
__generator = EAX ;
}
2015-07-22 20:32:54 +02:00
# endif