控制台程序输出传入参数随机时间关闭兼谈随机数

// jcall.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<iostream>
#include <comdef.h>
#include <random>
#include<time.h>
using namespace std;
using std::default_random_engine;
using std::uniform_int_distribution;
static default_random_engine e(time(nullptr));
uniform_real_distribution<double> u1(1, 4);
static double getrand();
int _tmain(int argc, _TCHAR* argv[])
{
	string st;
	for (int i = 1; i < argc; i++)
	{
		string temp = "\t";
		st += argv[i] + temp;
	}
	cout << "stdcout:  ";
	fprintf(stdout, st.data());
	cout << endl;
	cout << "stderr:  ";
	fprintf(stderr, st.data());
	cout << endl;
	//system("cls");
	double min = getrand();
	min = min * 1000 * 60;
	cout << "休眠"<<min/(1000*60)<<"分钟";
	Sleep(min);
	return EXIT_SUCCESS;
	//std::cout << "Argument " << i << " is " << argv[i] << endl;
}
static double getrand()
{
	double min = 1.2;
	for (int i = 0; i < 10; i++)
	{
		min = u1(e);
	}
	return min;
}

程序每次启动获取一个小于5的随机数

#include <iostream>
#include<cstdlib>
#include<ctime>
using namespace std;

int main()
{
    srand(time(0));
    for(int x=1;x<25;x++){
       cout << rand()%5)<< endl;
    }

    system("pause");
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值