Generate 0 and 1 with 25 % and 75 % probability | Java 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 ; Initialize random number generator srand ( time ( null ) ) ;
class GFG { static int rand50 ( ) { return ( int ) ( 10 * Math . random ( ) ) & 1 ; } static int rand75 ( ) { return rand50 ( ) | rand50 ( ) ; } public static void main ( String [ ] args ) { for ( int i = 0 ; i < 50 ; i ++ ) { System . out . print ( rand75 ( ) ) ; } } }