Created
May 20, 2017 11:32
-
-
Save bulv1ne/3304057a22aab591532e619a7dc50d0f to your computer and use it in GitHub Desktop.
Django random templatetag for random integers (mainly used in cache busting)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
from django import template | |
register = template.Library() | |
@register.simple_tag | |
def random_int(a, b=None): | |
''' | |
Return a random integer N such that `a <= N <= b` | |
If b is omitted, N is `a / 2 <= N <= a` | |
''' | |
if not b: | |
a, b = a // 2, a | |
return random.randint(a, b) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment