Return a valid random date.
166044
def random_date():
    ''''''
    d = datetime.datetime.now().date()
    d = d - datetime.timedelta(random.randint(20,2001))
    return d
372545
def get_random_id(length):
    """"""
    alphabet = string.ascii_uppercase + string.ascii_lowercase + string.digits
    return ''.join(random.choice(alphabet) for _ in range(length))
695885
def datetime(past=True, random=random):
    

    def year():
        if past:
            return random.choice(range(1950,2005))
        else:
            return _datetime.datetime.now().year + random.choice(range(1, 50))

    def month():
        return random.choice(range(1,12))

    def day():
        return random.choice(range(1,31))

    def hour():
        return random.choice(range(0,23))

    def minute():
        return random.choice(range(0,59))

    def second():
        return random.choice(range(0,59))

    try:
        return _datetime.datetime(year=year(),
                                  month=month(),
                                  day=day(),
                                  hour=hour(),
                                  minute=minute(),
                                  second=second())
    except ValueError:
        return datetime(past=past)
1374637
def pastdate(self, prompt, default=None):
        """"""
        prompt = prompt if prompt is not None else "Enter a past date"
        if default is not None:
            prompt += " [" + default.strftime('%d %m %Y') + "]"
        prompt += ': '
        return self.input(curry(filter_pastdate, default=default), prompt)
319800
def random_id(length):
    """"""

    def char():
        """Generate single random char"""

        return random.choice(string.ascii_letters + string.digits)

    return "".join(char() for _ in range(length))
43004
def rollforward(self, date):
        """"""
        if self.onOffset(date):
            return date
        else:
            return date + YearEnd(month=self.month)
15105
def _getFromDate(l, date):
    '''
    
    '''
    try:
        date = _toDate(date)
        i = _insertDateIndex(date, l) - 1
        if i == -1:
            return l[0]
        return l[i]
    except (ValueError, TypeError):
        # ValueError: date invalid / TypeError: date = None
        return l[0]
1204522
def randomString(length, chrs=None):
    """"""
    if chrs is None:
        return getBytes(length)
    else:
        n = len(chrs)
        return ''.join([chrs[randrange(n)] for _ in xrange(length)])
1098475
def random_val(index, tune_params):
    """"""
    key = list(tune_params.keys())[index]
    return random.choice(tune_params[key])
1212271
def _choice_from(self, key: str) -> str:
        """"""
        data = self._data[key]
        return self.random.choice(data)
1306694
function coerceDate(value) {
    if (value instanceof Date) {
        return value;
    }

    let timestamp = Date.parse(value);

    if (!isNaN(timestamp)) {
        return new Date(timestamp);
    }

    return value;
}
240422
def uniform(self, key, min_value=0., max_value=1.):
        """"""
        return min_value + self._random(key) * (max_value - min_value)
288128
def get_date_or_404(year, month, day):
    """"""
    try:
        return datetime.date(int(year), int(month), int(day))
    except ValueError:
        raise Http404
350227
public PlainDate random() {

        DateInterval interval = this.toCanonical();

        if (interval.isFinite() && !interval.isEmpty()) {
            long randomNum =
                ThreadLocalRandom.current().nextLong(
                    interval.getStartAsCalendarDate().getDaysSinceEpochUTC(),
                    interval.getEndAsCalendarDate().getDaysSinceEpochUTC() + 1);
            return PlainDate.of(randomNum, EpochDays.UTC);
        } else {
            throw new IllegalStateException("Cannot get random date in an empty or infinite interval: " + this);
        }

    }
1219743
function randTime (startTime, endTime) {
  let secStart = new Date(startTime).getTime() / 1000
  let secDiff = 0
  if (secStart < 0) {
    secDiff = new Date(endTime) / 1000 + Math.abs(secStart)
  } else {
    secDiff = ~~((new Date(endTime) - new Date(startTime)) / 1000)
  }
  let randSec = tools.rnd(0, secDiff)
  let resultSec = (new Date(startTime)).getTime() + randSec * 1000
  return new Date(resultSec).date2Str()
}
1023870
def simulate(self):
        """"""
        min_ = (-sys.maxsize - 1) if self._min is None else self._min
        max_ = sys.maxsize if self._max is None else self._max
        return random.randint(min_, max_)
589221
def make_random(cls):
        """"""
        self = object.__new__(cls)
        self.rank = Rank.make_random()
        self.suit = Suit.make_random()
        return self