Skip to content

Instantly share code, notes, and snippets.

@emillundh
emillundh / timing_weighted_choices.py
Created November 10, 2017 15:21
Timing some algorithms for weighted choices
import timeit
import random
import numpy as np
x = range(10)
y = [0.0, 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09]
ysum = sum(y)
y = [yi / ysum for yi in y]
# ===== Pure python methods
import functools
from channels.handler import AsgiRequest
from rest_framework.exceptions import AuthenticationFailed
from rest_framework.settings import api_settings
authenticators = [auth() for auth in api_settings.DEFAULT_AUTHENTICATION_CLASSES]