-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnoise.cpp
More file actions
40 lines (29 loc) · 753 Bytes
/
noise.cpp
File metadata and controls
40 lines (29 loc) · 753 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
#include <algorithm>
#include <iostream>
#include <iterator>
#include <random>
using namespace std;
int main() {
ios::sync_with_stdio(false);
random_device rd;
mt19937 gen(rd());
bernoulli_distribution ber_dist(0.25f);
uniform_int_distribution<uint8_t> uni_dist(0, 7);
cin >> noskipws;
istream_iterator<uint8_t> begin(cin), end;
bool prev = false;
transform(
begin, end,
ostream_iterator<uint8_t>(cout),
[&] (uint8_t v) -> uint8_t {
if (!prev && ber_dist(gen)) {
v ^= 1 << uni_dist(gen);
prev = true;
}
else {
prev = false;
}
return v;
});
return EXIT_SUCCESS;
}