// 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;
}