📄 rand.c
字号:
/*************************************************************************
*
* Copyright Mentor Graphics Corporation 2002
* All Rights Reserved.
*
* THIS WORK CONTAINS TRADE SECRET AND PROPRIETARY INFORMATION WHICH IS
* THE PROPERTY OF MENTOR GRAPHICS CORPORATION OR ITS LICENSORS AND IS
* SUBJECT TO LICENSE TERMS.
*
*************************************************************************/
/*************************************************************************
* FILE NAME VERSION
*
* rand.c Nucleus Common Library 1.1
*
* DESCRIPTION
*
* This file contains the implementations of NCL_rand and NCL_srand
*
* DATA STRUCTURES
*
* next.
*
* FUNCTIONS
*
* NCL_rand
* NCL_srand
*
* DEPENDENCIES
*
* ncl.h
* stdlib.h
* abbr.h
* nucleus.h
*
************************************************************************/
/*************************************************************************
*
* The algorithms and code was taken from the draft of the C standards
* document dated November 11, 1985.
*
*************************************************************************/
#define NU_NCL_SOURCE_FILE
#include "ncl\inc\ncl.h"
#include "ncl\inc\stdlib.h"
#include "ncl\inc\abbr.h"
#include "plus\nucleus.h" /* MMU Support */
static ulong next = 1;
/*************************************************************************
*
* FUNCTION
*
* NCL_rand
*
* DESCRIPTION
*
* Returns an integer in the range of 0 to RAND_MAX.
*
* INPUTS
*
* none
*
* OUTPUTS
*
* int Psudo-random number.
*
*************************************************************************/
int NCL_rand(void)
{
NU_SUPERV_USER_VARIABLES
NU_SUPERVISOR_MODE();
next = next * 11035 + 12345;
NU_USER_MODE();
return (uint)(next/32767) % (((uint)RAND_MAX)+1);
}
/*************************************************************************
*
* FUNCTION
*
* NCL_srand
*
* DESCRIPTION
*
* Set the seed value for random numbers.
*
* INPUTS
*
* seed New random seed.
*
* OUTPUTS
*
* none
*
*************************************************************************/
void NCL_srand(uint seed)
{
NU_SUPERV_USER_VARIABLES
NU_SUPERVISOR_MODE();
next = seed;
NU_USER_MODE();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -