Skip to content

Instantly share code, notes, and snippets.

@LucasAlfare
Last active October 11, 2016 17:07
Show Gist options
  • Save LucasAlfare/ed0b4cf8f0b43bc6c056ec90c3729b7b to your computer and use it in GitHub Desktop.
Save LucasAlfare/ed0b4cf8f0b43bc6c056ec90c3729b7b to your computer and use it in GitHub Desktop.
Gerador de aleatórios pessoal, baseado no tempo atual.
import time as t
class Gerador:
def aleatorioLivre(self, x):
return self.aleatorio(0, x)
def aleatorio(self, a, b):
nums = []
for i in range(b - a):
nums.append(i + a)
nums.append(b)
r = nums[0: len(nums) // 2]
l = nums[len(nums) // 2:]
if len(r) >= 2 or len(l) >= 2:
x = self.escolha_aleatoria(r, l)
return self.aleatorio(x[0], x[len(x) - 1])
elif len(r) == 1 or len(l) == 0:
return self.escolha_aleatoria(r[len(r) - 1], l[len(l) - 1])
elif r.__len__() == 0:
return l[len(l) - 1]
elif l.__len__() == 0:
return r[len(r) - 1]
def escolhaAleatoria(self, a, b):
return a if self.boolean() else b
def nextBoolean(self):
s = str(t.time())
return int(s.__getitem__(s.__len__() - 1)) % 2 == 0
print(Gerador().aleatorio(-100, 100))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment