-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandom.cpp
More file actions
46 lines (34 loc) · 776 Bytes
/
Copy pathRandom.cpp
File metadata and controls
46 lines (34 loc) · 776 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//
// Created by mateus558 on 25/08/17.
//
#include "Random.h"
#include <random>
#include <vector>
namespace Random {
std::minstd_rand gen;
void init() {
gen.seed(std::random_device{} ());
}
int intInRange(int low, int high) {
std::uniform_int_distribution<int> dist(low, high);
return dist(gen);
}
float floatInRange(float low, float high) {
std::uniform_real_distribution<float> dist(low, high);
return dist(gen);
}
std::vector<int> randomArray(int n){
int i, j, temp;
std::vector<int> arr(n+1);
for(i = 0; i <= n; i++){
arr[i] = i;
}
for(i = 0; i <= n; i++){
j = intInRange(0, n);
temp = arr[j];
arr[j] = arr[i];
arr[i] = temp;
}
return arr;
}
}