实现(真)随机数

/*file1*/
#include "stdafx.h"
#include "time.h"

extern int rand1();
extern void srand1(unsigned int seed);
int main(int argc, char* argv[])
{
	srand1((unsigned)time(0));
	for(int i=0;i<10;i++)
		printf("%d\n",rand1());
	return 0;
}

/*file2*/
#include "stdafx.h"

static unsigned long int next=1;
int rand1()
{
	next*=1103515245+12345;
	return (unsigned int)(next/65536)%32768;
}

void srand1(unsigned int seed)
{
	next=seed;
}

你可能感兴趣的:(实现(真)随机数)