C++产生m到n之间的随机数,产生0到100之间的随机数,以系统时间作为随机种子
2011-10-28 20:52
501 查看
// 随机数产生.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<iostream>
#include<ctime>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int i =0 ;
cout<<"产生10个0到100之间的随机数:"<<endl;
srand((unsigned)time(NULL)); //以系统时间作为随机种子
for(i=0;i<10;i++)
{
cout<<rand()%100<< " ";
}
cout<<endl;
cout<<"请输入需要产生m到n之间的随机数的m与n的值:"<<endl;
int m,n;
cin>>m>>n;
cout<<"产生10个 "<<m<<" 到 "<<n<<" 之间的随机数:"<<endl;
srand((unsigned)time(NULL)); //以系统时间作为随机种子
for(i=0;i<10;i++)
{
cout<<m + rand()%(n-m+1)<< " ";
}
cout<<endl;
system("pause");
return 0;
}
//
#include "stdafx.h"
#include<iostream>
#include<ctime>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int i =0 ;
cout<<"产生10个0到100之间的随机数:"<<endl;
srand((unsigned)time(NULL)); //以系统时间作为随机种子
for(i=0;i<10;i++)
{
cout<<rand()%100<< " ";
}
cout<<endl;
cout<<"请输入需要产生m到n之间的随机数的m与n的值:"<<endl;
int m,n;
cin>>m>>n;
cout<<"产生10个 "<<m<<" 到 "<<n<<" 之间的随机数:"<<endl;
srand((unsigned)time(NULL)); //以系统时间作为随机种子
for(i=0;i<10;i++)
{
cout<<m + rand()%(n-m+1)<< " ";
}
cout<<endl;
system("pause");
return 0;
}
相关文章推荐
- C++中的srand(time(null))利用时间设置随机种子产生随机数
- C++中的srand(time(null))利用时间设置随机种子产生随机数
- C++中的srand(time(null))利用时间设置随机种子产生随机数
- C++中的srand(time(null))利用时间设置随机种子产生随机数 http://blog.csdn.net/youoran/article/details/10950671
- C++中的srand(time(null))利用时间设置随机种子产生随机数
- 随机产生1-100之间的20个随机数
- 时间作为种子(随机数的产生)
- 设计程序,单击【随机数】按钮,使用Math对象的random函数产生一个0-100之间(含0-100)的随机整数,并在对话框中显示,如下图。单击【计算】按钮,计算该随机数的平方、平方根和自然对数,保留两位小数,并在对话框中显示,如下图。
- C++利用系统时间产生的随机数
- 读取系统时间作为seed 随机打印数字
- C++ 随机数与随机种子数的实例
- Fortran 随机数产生的子程序(调用系统时间单位为毫秒)
- 面试题:产生一个长度为100的数组,为数组中的每一项随机填充1-100之间的数并且保证不重复
- matlab根据读取系统时间产生比较靠谱的随机数
- js随机产生40个60至100之间的不相同的数字存入数组并顺序排序
- flash中随机产生20-100之间10个不同的数字,然后不能重复地随机取出这十个数字
- PHP利用rand(1,100)函数产生10个1~100之间的随机数
- 面试题:产生一个长度为100的数组,为数组中的每一项随机填充1-100之间的数并且保证不重复
- C/C++产生[m, n)之间不重复的随机序
- java中产生0-100之间的随机整数