Generate 0 and 1 with 25 % and 75 % probability | Program to print 1 with 75 % probability and 0 with 25 % probability ; Random Function to that returns 0 or 1 with equal probability ; rand ( ) function will generate odd or even number with equal probability . If rand ( ) generates odd number , the function will return 1 else it will return 0. ; Random Function to that returns 1 with 75 % probability and 0 with 25 % probability using Bitwise OR ; Driver code to test above functions ; Initialize random number generator
#include <iostream> NEW_LINE using namespace std ; int rand50 ( ) { return rand ( ) & 1 ; } bool rand75 ( ) { return rand50 ( ) | rand50 ( ) ; } int main ( ) { srand ( time ( NULL ) ) ; for ( int i = 0 ; i < 50 ; i ++ ) cout << rand75 ( ) ; return 0 ; }