// radomtest.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <math.h>
#include <stdlib.h>
#include <memory.h>
#include <vector>
#include <time.h>
using namespace std;
#define LENGTH 1000;
int* random_number(int minValue,int maxValue,int length);
int main(int argc, char* argv[])
{
printf("Hello World!\n");
int minValue = 1;
int maxValue = LENGTH;
int count = 15;
int* rand_num = random_number(minValue,maxValue,count);
for (int i = 0; i < 15; i++)
{
printf("%d ",rand_num[i]);
}
delete[] rand_num;
return 0;
}
int* random_number(int minValue,int maxValue,int length)
{
if (minValue > maxValue)
return NULL;
if (maxValue - minValue < length)
return NULL;
if (minValue < 0)
return NULL;
vector<int> ran_num;
int* ret = new int[length];
memset(ret,0,sizeof(int)*length);
int j = 0;
for (int i = minValue; i <= maxValue; i++)
{
ran_num.push_back(i);
}
srand(time(0));
for (int m = 0; m < length; m++)
{
int n = rand()%LENGTH;
n = n >= ran_num.size() ? ran_num.size()-1 : n;
int a = *(ran_num.begin()+n);
ret[m] = a;
ran_num.erase(ran_num.begin()+n);
}
return ret;
}