Skip to content

Instantly share code, notes, and snippets.

@Khrol
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Khrol/015d52d2de73ba07d483 to your computer and use it in GitHub Desktop.
Save Khrol/015d52d2de73ba07d483 to your computer and use it in GitHub Desktop.
from random import randint
from math import copysign
def generate(exception, n):
x = randint(1, n - 1)
if x >= exception:
return x + 1
return x
def generate_math(exception, n):
x = randint(1, n - 1)
return int(x + (copysign(1, x - exception) + 1) / 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment