Skip to content

Commit

Permalink
random num generator
Browse files Browse the repository at this point in the history
  • Loading branch information
piyush01123 committed Feb 28, 2019
1 parent baecfc1 commit fedc790
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
3 changes: 3 additions & 0 deletions 90/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This question was asked by Google.

Given an integer n and a list of integers l, write a function that randomly generates a number from 0 to n-1 that isn't in l (uniform).
13 changes: 13 additions & 0 deletions 90/sol.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

import random

def generateRandom(n: int, l: list):
A = [num for num in range(n) if num not in l]
while True:
idx = random.randint(0, len(A)-1)
yield A[idx]

if __name__=='__main__':
gen = generateRandom(n=10, l=[3, 8, 12, 20])
for _ in range(25):
print(gen.__next__())
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,5 @@ If you are looking to help out a fellow programmer, please head over to the [Iss
| 86 | [Min parantheses removal](86) | Google | Solved | Python |
| 87 | [Validate Map](87) | Uber | Solved | Python |
| 88 | [Integer division](88) | ContextLogic | Solved | Python |
| 89 | [Valid BST](88) | LinkedIn | Solved | Python |
| 89 | [Valid BST](89) | LinkedIn | Solved | Python |
| 90 | [Random number generator with exception rule](90) | Google | Solved | Python |

0 comments on commit fedc790

Please sign in to comment.