home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume36
/
formes
/
part01
/
random.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-04-01
|
1KB
|
83 lines
/*
* Copyright (C) 1992-1993 Jeffrey Chilton
*
* Permission is granted to anyone to make or distribute copies of
* this program, in any medium, provided that the copyright notice
* and permission notice are preserved, and that the distributor
* grants the recipient permission for further redistribution as
* permitted by this notice.
*
* Author's E-mail address: 172-9221@mcimail.com
*
*/
static char *whatstring = "@(#)random.c 2.2 JWC";
#include <stdio.h>
#include <malloc.h>
#include "class.h"
#include "random.h"
#if TESTMAIN
main()
{
register int i;
Random *squiz;
long l;
squiz = Random_new();
for (i = 0; i < 10000; i++)
{
l = Random_long(squiz);
putchar(l & 0xFF);
}
}
#endif
Random *
Random_new()
{
Random *self;
self = (Random *)malloc(sizeof (Random));
if (self)
{
*self = time((long *)0);
}
return self;
}
long
Random_long(self)
Random *self;
{
long t;
/* New seed is absolute value of Squizzing's function applied to old */
t = *self;
t = t / 5L ^ t * 6L;
if (t < 0L)
{
t = -t;
}
*self = t;
return t;
}
void
Random_destroy(self)
Random *self;
{
free(self);
}