Skip to content

Instantly share code, notes, and snippets.

@salma71
Created December 31, 2020 14:56
Show Gist options
  • Save salma71/b3d4786673bdb4bae3d56caaebf1cd49 to your computer and use it in GitHub Desktop.
Save salma71/b3d4786673bdb4bae3d56caaebf1cd49 to your computer and use it in GitHub Desktop.
from typing import List
import random
def random_sampling(k: int, array_list: List[int]) -> None:
"""high level support for doing this and that."""
for i in range(k):
random_index = random.randint(i, len(array_list) - 1)
# swap element based on the generated index
array_list[i], array_list[random_index] = array_list[random_index], array_list[i]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment