10% for 0, 90% for 1

I need to make function that will have 10% that variable (in this case its float) will be 0, and 90% that it will be 1.
How to??? :(

I have:

float reflection;
if (angle <= Brewster_angle){
(it will have 100% chanse to reflect)
reflection = 1;
}
else {
it will have 90% chanse to reflect, and 10% chanse to transmit)
reflection = ....
}

i.e.:
value for reflection is 1 or 0; if angle>Brewster_angle there is 90% chanse that float reflection = 1, and 10% chanse that float reflection = 0.
http://www.cplusplus.com/reference/random/uniform_real_distribution/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <random>
#include <chrono>

int main()
{
  unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();

  std::default_random_engine generator( seed );
  std::uniform_real_distribution<double> distribution( 0.0, 1.0 );

  double number = distribution( generator );
  if ( number < 0.7 ) std::cout << "In the 70%\n";
  return 0;
}



Edit: the bernoulli is more on the point.

Interesting seeding of the generator in:
http://www.cplusplus.com/reference/random/bernoulli_distribution/bernoulli_distribution/
Last edited on
Topic archived. No new replies allowed.