srand.c 1.17 KB
/*
=============================================================================
        Copyright (C) 1997-1999 NINTENDO Co.,Ltd.
        
        $RCSfile: srand.c,v $
        $Revision: 1.1.1.1 $
        $Date: 2002/10/30 02:07:09 $
=============================================================================
関数名:srand
-----------------------------------------------------------------------------
書式:  #include <stdlib.h>
        void srand(unsigned seed);
引数:  seed 乱数の種
戻り値:なし
説明:  関数 rand() が返す擬似乱数の種を指定する。
=============================================================================
関数名:rand
-----------------------------------------------------------------------------
書式:  #include <stdlib.h>
        int rand(void);
引数:  なし
戻り値:擬似乱数を返す
説明:  0〜0x7fffまでの擬似乱数を返す。
-----------------------------------------------------------------------------
*/
#include <stdlib.h>

/* #define RAND_MAX    0x7fff move to math.h */
static  unsigned rand_data;

void srand(unsigned seed)
{
    rand_data = seed;
}

int rand(void)
{
    rand_data *= 20077;
    rand_data += 12345;
    return  (rand_data >> 16) & RAND_MAX;
}