Generate a random Binary String of length N | Function to find a random number between 0 or 1 ; Generate the random number ; Return the generated number ; Function to generate a random binary string of length N ; Stores the empty string ; Iterate over the range [ 0 , N - 1 ] ; Store the random number ; Append it to the string ; Print the resulting string ; Driver Code
function findRandom ( ) { let num = ( 1 + parseInt ( ( Math . random ( ) * 100 ) ) ) % 2 ; return num ; } function generateBinaryString ( N ) { let S = " " ; for ( let i = 0 ; i < N ; i ++ ) { let x = findRandom ( ) ; S += ( x ) . toString ( ) ; } document . write ( S ) } let N = 7 ; generateBinaryString ( N ) ;