Helper function which prints a sequence of `num` items
    produced by the random generator `gen`.
193091
def print_generated_sequence(gen, num, *, sep=", ", fmt='', seed=None):
    
    if seed:
       gen.reset(seed)

    elems = [format(next(gen), fmt) for _ in range(num)]
    sep_initial = "\n\n" if '\n' in sep else " "
    print("Generated sequence:{}{}".format(sep_initial, sep.join(elems)))
170411
def command_gen(self, *names):
        '''
        
        '''
        if not names:
            sys.exit('Please provide generator names')
        for name in names:
            name, count = name, 0
            if ':' in name:
                name, count = name.split(':', 1)
            count = int(count)
            create = self.generators[name]
            print('Generating `{0}` count={1}'.format(name, count))
            create(self.session, count)
            self.session.commit()
909165
function(sequence, n, startSymbol, endSymbol, stats) {
    var result = [];
    frequencies = {};
    nrOfNgrams = 0;
    
    if (!_(sequence).isArray()) {
        sequence = tokenizer.tokenize(sequence);
    }

    var count = _.max([0, sequence.length - n + 1]);

    // Check for left padding    
    if(typeof startSymbol !== "undefined" && startSymbol !== null) {
        // Create an array of (n) start symbols
        var blanks = [];
        for(var i = 0 ; i < n ; i++) {
            blanks.push(startSymbol);
        }

        // Create the left padding
        for(var p = n - 1 ; p > 0 ; p--) {
            // Create a tuple of (p) start symbols and (n - p) words
          var ngram = blanks.slice(0, p).concat(sequence.slice(0, n - p));
          result.push(ngram);
          if (stats) {
            countNgrams(ngram);
          }
        }
    }

    // Build the complete ngrams
    for (var i = 0; i < count; i++) {
        var ngram = sequence.slice(i, i + n);
        result.push(ngram);
        if (stats) { 
          countNgrams(ngram);
        }
    }

    // Check for right padding
    if(typeof endSymbol !== "undefined" && endSymbol !== null) {
        // Create an array of (n) end symbols
        var blanks = [];
        for(var i = 0 ; i < n ; i++) {
            blanks.push(endSymbol);
        }

        // create the right padding
        for(var p = n - 1 ; p > 0 ; p--) {
            // Create a tuple of (p) start symbols and (n - p) words
          var ngram = sequence.slice(sequence.length - p, sequence.length).concat(blanks.slice(0, n - p));
          result.push(ngram);
          if (stats) {
            countNgrams(ngram);
          }
        }
    }
    
    if (stats) {
      
      // Count frequencies
      var Nr = {};
      Object.keys(frequencies).forEach(function(key) {
        if (!Nr[frequencies[key]]) {
          Nr[frequencies[key]] = 0;
        }
        Nr[frequencies[key]]++;
      });
      
      // Return the ngrams AND statistics
      return {
        "ngrams": result,
        "frequencies": frequencies,
        "Nr": Nr,
        "numberOfNgrams": nrOfNgrams
      };
      
    }
    else { // Do not break existing API of this module 
      return result;
    }
}
379182
def string_for_count(dictionary, count):
    """"""
    string_to_print = ""
    if count is not None:
        if count == 0:
            return ""
        ranger = count
    else:
        ranger = 2
    for index in range(ranger):
        string_to_print += "{} ".format(get_random_word(dictionary))

    return string_to_print.strip()
110735
def getRandomSequence(length=500):
    
    fastaHeader = ""
    for i in xrange(int(random.random()*100)):
        fastaHeader = fastaHeader + random.choice([ 'A', 'C', '0', '9', ' ', '\t' ])
    return (fastaHeader, \
            "".join([ random.choice([ 'A', 'C', 'T', 'G', 'A', 'C', 'T', 'G', 'A', 'C', 'T', 'G', 'A', 'C', 'T', 'G', 'A', 'C', 'T', 'G', 'N' ]) for i in xrange((int)(random.random() * length))]))
1310903
function _generateRandomInteger( nMin, nMax )
{
	return Math.floor( Math.random() * ( nMax + 1 - nMin ) ) + nMin;
}
875407
def createRandomSequences(self,
                          numSequences,
                          sequenceLength):
    
    for _ in xrange(numSequences):
      self.addObject(
        [numpy.random.randint(0, self.numFeatures)
                                            for _ in xrange(sequenceLength)]
      )
508193
def _generate_serial2(func, args_gen, kw_gen=None, ntasks=None, progkw={},
                      verbose=None, nTasks=None):
    
    if verbose is None:
        verbose = 2
    if ntasks is None:
        ntasks = nTasks
    if ntasks is None:
        ntasks = len(args_gen)
    if verbose > 0:
        print('[ut._generate_serial2] executing %d %s tasks in serial' %
                (ntasks, get_funcname(func)))

    # kw_gen can be a single dict applied to everything
    if kw_gen is None:
        kw_gen = [{}] * ntasks
    if isinstance(kw_gen, dict):
        kw_gen = [kw_gen] * ntasks

    # Get iterator with or without progress
    if verbose > 1:
        lbl = '(sergen) %s: ' % (get_funcname(func),)
        progkw_ = dict(freq=None, bs=True, adjust=False, freq_est='between')
        progkw_.update(progkw)
        args_gen = util_progress.ProgIter(args_gen, length=ntasks, lbl=lbl,
                                          **progkw_)

    for args, kw in zip(args_gen, kw_gen):
        result = func(*args, **kw)
        yield result
1097496
def generate(self, num_to_generate, starting_place):
        """"""
        res = []
        activ = starting_place[None, :]
        index = activ.__getattribute__(self.argfunc)(1)
        item = self.weights[index]
        for x in range(num_to_generate):
            activ = self.forward(item, prev_activation=activ)[0]
            index = activ.__getattribute__(self.argfunc)(1)
            res.append(index)
            item = self.weights[index]

        return res
1058702
def gen_random_string(str_len):
    
    return ''.join(
        random.choice(string.ascii_letters + string.digits) for _ in range(str_len))
988904
def gen_n_random_num(n, MAX_NUM=MAX_INT, unique=True):
    
    fmt = "<%dI" % n
    t = struct.calcsize(fmt)
    D = [d % MAX_NUM for d in struct.unpack(fmt, os.urandom(t))]
    if unique:
        D = set(D)
        assert MAX_NUM > n, \
            "Cannot have {0} unique integers less than {1}".format(n, MAX_NUM)
        while len(D) < n:
            print("Number of collision: {}. Regenerating!".format(n - len(D)))
            fmt = "<%dI" % (n - len(D))
            t = struct.calcsize(fmt)
            extra = struct.unpack(fmt, os.urandom(t))
            D |= set(d % MAX_NUM for d in extra)
        D = list(D)
    return D
1360080
def genfirstvalues(cursor: Cursor, arraysize: int = 1000) \
        -> Generator[Any, None, None]:
    
    return (row[0] for row in genrows(cursor, arraysize))
636748
def generate_datafile(number_items=20000):
    
    from utils import generate_dataset_shelve
    filename = "samples.shelve"
    dataset = generate_dataset_shelve(filename, number_items)
    print "%s generated with %d samples" % (filename, number_items)
1020595
def generate_batches(sequence, batch_len=1, allow_partial=True, ignore_errors=True, verbosity=1):
    
    it = iter(sequence)
    last_value = False
    # An exception will be thrown by `.next()` here and caught in the loop that called this iterator/generator
    while not last_value:
        batch = []
        for n in range(batch_len):
            try:
                batch += (next(it),)
            except StopIteration:
                last_value = True
                if batch:
                    break
                else:
                    raise StopIteration
            except Exception:
                # 'Error: new-line character seen in unquoted field -
                # do you need to open the file in universal-newline mode?'
                if verbosity > 0:
                    print_exc()
                if not ignore_errors:
                    raise
        yield batch
1372508
def recgen_enumerate(gen,n=tuple(), fix_type_errors=True):
    
    if not hasattr(gen,'__iter__'):
        yield (n,gen)
    else:
        try:
            for i_,i in enumerate(gen):
                for element in recgen_enumerate(i,n+(i_,)):
                    yield element
        except TypeError:
            if not fix_type_errors:
                raise
            yield (n,gen)
1251693
function randNum (n) {
  let sNum = ''
  for (let i = 0; i < n; i++) {
    sNum += tools.rnd(0, 9)
  }
  return sNum
}
622174
def _genA(self):
        
        p, df = self._p, self.df
        A = np.zeros((p, p))

        for i in range(p):
            A[i, i] = sqrt(st.chi2.rvs(df - i))

        for j in range(p-1):
            for i in range(j+1, p):
                A[i, j] = np.random.randn()

        return A