|
|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T s
Length: 811 (0x32b)
Types: TextFile
Names: »shuf.c«
└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987
└─⟦this⟧ »EUUGD18/General/Nobs/shuf.c«
/*
* shuf - shuffle the pack.
*/
#include "defs.h"
#include "globs.h"
#ifdef BSD
int srand();
int rand();
#else
void srand48();
double drand48();
#endif
static makepack();
void
shuf()
{
int j, k;
CARD dummy;
if (!packmade) makepack();
for (j=51; j>=39; j--) {
k = randint(j+1);
dummy = pack[k];
pack[k] = pack[j];
pack[j] = dummy;
}
}
static
makepack()
{
int suit, rank;
CARD *packp;
packp = pack;
for (suit=CLUB; suit<=SPADE; suit++)
for (rank=ACE; rank<=KING; rank++)
*packp++ = MAKECARD(rank,suit);
}
initrand()
{
long time();
#ifdef BSD
srand(time((long *)0));
rand();
#else
srand48(time((long *)0));
drand48();
#endif
}
/*
* Returns a random integer from 0 to n-1.
*/
int
randint(n)
int n;
{
#ifdef BSD
return (rand()/3) % n;
#else
return (int)(drand48()*n);
#endif
}