GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing www.geeksforgeeks.org — Python Program to Generate Random binary string - GeeksforGeeks Python Program to Generate Random binary stringLast Updated : 17 Mar, 2023 Given a number n, the task is to generate a random binary string of length n. Input: 7 Output: Desired length of random binary string is: 1000001 Input: 5 Output: Desired length of random binary string is: 01001
Below is the implementation.
Output: Desired length random binary string is: 1000001 The Time and Space Complexity for all the methods are the same: Time Complexity: O(n) Auxiliary Space: O(n) Using random.getrandbits():
Output Random binary string of length 7: 1010000 Explanation: The random.getrandbits(n) function generates a random number with n bits. Time Complexity: O(n), where n is the number of bits in the binary string. Auxiliary Space: O(n), where n is the number of bits in the binary string. This is the space required to store the binary string. Comment Explore |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |