You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
790 B
40 lines
790 B
from django.utils import timezone
|
|
import pydash as _; _.map = _.map_; _.filter = _.filter_
|
|
import random
|
|
|
|
|
|
def take(coll, n):
|
|
chunk = coll[0:n]
|
|
del coll[0:n]
|
|
return chunk
|
|
|
|
|
|
def take_random(coll, n):
|
|
if n == 0:
|
|
return []
|
|
|
|
chunk = _.sample(coll, n)
|
|
|
|
for item in chunk:
|
|
coll.remove(item)
|
|
|
|
return chunk
|
|
|
|
|
|
def take_one_random(coll):
|
|
if len(coll) == 0:
|
|
return None
|
|
|
|
return coll.pop(_.random(0, len(coll)-1))
|
|
|
|
|
|
def random_phone():
|
|
return '+7' + str(_.sample((917, 964, 965, 987, 912, 935))) + str(_.random(1000000, 9999999))
|
|
|
|
|
|
def random_date():
|
|
return timezone.datetime(_.random(2012, 2018), _.random(1, 12), _.random(1, 28))
|
|
|
|
|
|
def random_amount():
|
|
return random.random() * random.choice((100, 1000, 10000))
|
|
|