while( (diceroll = (random()%32)) >= 20 ) { create_lag(); }
diceroll = random() % 20;
skill = 75
value = [88, 100, 23, 459, skill].min
value = [100, skill].min
[1, 10, 100, 1000].max
[1, [100, skill].min].max
i = minmax(1, value, 100);
#if defined (OLD_RAND)
static int rgiState[2+55];
#elif defined (TYCHE_RAND)
static long rgiState[32] = {
0x00000011, 0x9a319039, 0x32d9c024, 0x9b663182, 0x5da1f342, 0xde3b81e0, 0xdf0a6fb5, 0xf103bc02,
0x48f340fb, 0x7449e56b, 0xbeb1dbb0, 0xab5c5918, 0x946554fd, 0x8c2e680f, 0xeb3d799f, 0xb11ee0b7,
0x2d436b86, 0xda672e2a, 0x1588ca88, 0xe369735d, 0x904f35f7, 0xd7158fd6, 0x6fa6f051, 0x616e6b96,
0xac94efdc, 0x36413f93, 0xc622c298, 0xf5a42ab8, 0x8a88d77b, 0xf5ad9d0e, 0x8999220b, 0x27fb47b9
};
static long *fp = &rgiState[4];
static long *rp = &rgiState[1];
static long *piState = &rgiState[1];
#endif
long number_mm( void )
{
#if defined (OLD_RAND)
int *piState;
int iState1;
int iState2;
int iRand;
piState = &rgiState[2];
iState1 = piState[-2];
iState2 = piState[-1];
iRand = (piState[iState1] + piState[iState2])
& ((1 << 30) - 1);
piState[iState1] = iRand;
if ( ++iState1 == 55 )
iState1 = 0;
if ( ++iState2 == 55 )
iState2 = 0;
piState[-2] = iState1;
piState[-1] = iState2;
return iRand >> 6;
#elif defined (TYCHE_RAND)
long i;
*fp += *rp; i = (*fp >> 1) & 0x7fffffff;
if (++fp >= &rgiState[32]) {fp = piState;++rp;
} else if (++rp >= &rgiState[32]) rp = piState;
return(i >> 6);
#else
return random() >> 6;
#endif
}
void init_mm( )
{
#if defined (OLD_RAND)
int *piState;
int iState;
piState = &rgiState[2];
piState[-2] = 55 - 55;
piState[-1] = 55 - 24;
piState[0] = ((int) current_time) & ((1 << 30) - 1);
piState[1] = 1;
for ( iState = 2; iState < 55; iState++ )
{
piState[iState] = (piState[iState-1] + piState[iState-2])
& ((1 << 30) - 1);
}
#elif defined (TYCHE_RAND)
int i, j = 1;
piState[0] = time(NULL);
for (i = 1; i < 31; i++) piState[i] = 1103515245 * piState[i - 1] + 12345;
fp = &piState[3]; rp = &piState[0];
for (i = 0; i < 10 * 31; i++) number_mm();
#else
srandom(time(NULL)^getpid());
#endif
return;
}
$rng = [1,2,3]
def random
$rng.rotate!
return $rng[0]
end
# get a "random" number between 1 and 3.
while((value = random()) != 3) ; # Can't infinite loop
The question: Has anyone else put hitroll into the equation before and how did it go?
Also while rolling out the final chances to hit you have:
/*
* The moment of excitement!
*/
while ((diceroll = number_bits (5)) >= 20);
if (diceroll == 0 || (diceroll != 19 && diceroll < thac0 - victim_ac))
{
/* Miss. */
damage (ch, victim, 0, dt, dam_type, TRUE);
tail_chain ();
return;
}
in db.c I found:
int number_bits (int width)
{
return number_mm () & ((1 << width) - 1);
}
… and the question to all that code is, does anyone have a decent explanation for now number_bits works?