rand.pc

来自「UNIX - AIX 下」· PC 代码 · 共 32 行

PC
32
字号
//原理如下:可产生0——32768间的随机数
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <cctype>
using namespace std;
const int NUM = 26;

/*int rand(void)
{
    next=next*1103515245+12345;
    return(unsigned int)(next/65536)%32768;
//32768是随机数的最大值,是可变的
}


void srand(unsigned int seed)
//seed作为种子改变next的值,从而影响rand函数中的返回数
{
		next=seed;
}*/


int main(int argc, char *argv[])
{
		int sa;
		//srand(time(NULL));//以时间作为种子
		sa=rand()%10;
		cout<<sa<<endl;
}  

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?