Generate 0 and 1 with 25 % and 75 % 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 ; This code is contributed m_kit
< ? php function rand50 ( ) { return rand ( ) & 1 ; } function rand75 ( ) { return rand50 ( ) | rand50 ( ) ; } srand ( time ( NULL ) ) ; for ( $ i = 0 ; $ i < 50 ; $ i ++ ) echo rand75 ( ) ; ? >