Initialize a new instance.

 Options:

 * :randomizer => Random.new # must respond to #rand(limit)
 * :source_parser => SourceParser.new options
 Given a word, return a weighted-randomly selected next-one.
511493
def next_word(word,randomizer=@randomizer)
    return if !markov_chains[word]
    sum = @markov_weighted_sum[word]
    random = randomizer.rand(sum)+1
    partial_sum = 0
    (markov_chains[word].find do |w, count|
      partial_sum += count
      w!=word && partial_sum >= random
    end||[]).first
  end
494070
public Random getNewRandomInstance(long seed, long size) {
        try {
            Class<?> c = randomClass;
            Constructor<?> constructor = c.getConstructor(long.class, long.class);
            Random t = (Random) constructor.newInstance(seed, size);
            return t;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
942048
def _rand_init(x_bounds, x_types, selection_num_starting_points):
    '''
    
    '''
    return [lib_data.rand(x_bounds, x_types) for i \
                    in range(0, selection_num_starting_points)]
537155
def new(cls, gen: Generator, sign_key: SignKey) -> 'VerKey':
        
        logger = logging.getLogger(__name__)
        logger.debug("VerKey::new: >>>")

        c_instance = c_void_p()
        do_call(cls.new_handler, gen.c_instance, sign_key.c_instance, byref(c_instance))

        res = cls(c_instance)

        logger.debug("VerKey::new: <<< res: %r", res)
        return res
482269
def first(self, **kwargs):
        
        result = result = self._get(limit=1, **kwargs)
        if result:
            return result[0]
        else:
            raise self.source_class.DoesNotExist(repr(kwargs))
357996
def new(cls) -> 'Generator':
        
        logger = logging.getLogger(__name__)
        logger.debug("Generator::new: >>>")

        c_instance = c_void_p()
        do_call(cls.new_handler, byref(c_instance))

        res = cls(c_instance)

        logger.debug("Generator::new: <<< res: %r", res)
        return res
956767
private static void initIdGenerator() {
		String workerID = Config.WORKER_ID;
		workerId = NumberUtils.toLong(workerID, 1);

		if (workerId > MAX_WORKER_ID || workerId < 0) {
			workerId = new Random().nextInt((int) MAX_WORKER_ID + 1);
		}

		if (dataCenterId > MAX_DATACENTER_ID || dataCenterId < 0) {
			dataCenterId =  new Random().nextInt((int) MAX_DATACENTER_ID + 1);
		}
	}
1235589
private void initializeCommonOptions(OptionParser parser) {
    helpOpt = parser.acceptsAll(Arrays.asList("help", "h"), "Print this help message.");

    randomSeed = parser.accepts("randomSeed", "Seed to use for generating random numbers. "
        + "Program execution may still be nondeterministic, if multithreading is used.").
        withRequiredArg().ofType(Long.class).defaultsTo(0L);
    
    noPrintOptions = parser.accepts("noPrintOptions", "Don't print out the command-line options "
        + "passed in to this program or final runtime statistics.");

    if (opts.contains(CommonOptions.STOCHASTIC_GRADIENT)) {
      sgdIterations = parser.accepts("iterations",
          "Number of iterations (passes over the data) for stochastic gradient descent.").
          withRequiredArg().ofType(Long.class).defaultsTo(10L);
      sgdBatchSize = parser.accepts("batchSize",
          "Minibatch size, i.e., the number of examples processed per gradient computation. If unspecified, defaults to using the entire data set (gradient descent).")
          .withRequiredArg().ofType(Integer.class);
      sgdInitialStep = parser.accepts("initialStepSize",
          "Initial step size for stochastic gradient descent.")
          .withRequiredArg().ofType(Double.class).defaultsTo(1.0);
      sgdNoDecayStepSize = parser.accepts("noDecayStepSize",
          "Don't use a 1/sqrt(t) step size decay during stochastic gradient descent.");
      sgdNoReturnAveragedParameters = parser.accepts("noReturnAveragedParameters", 
          "Get the average of the parameter iterates of stochastic gradient descent.");
      sgdL2Regularization = parser.accepts("l2Regularization",
          "Regularization parameter for the L2 norm of the parameter vector.")
          .withRequiredArg().ofType(Double.class).defaultsTo(0.0);
      sgdRegularizationFrequency = parser.accepts("regularizationFrequency",
          "Fraction of iterations on which to apply regularization. Must be between 0 and 1")
          .withRequiredArg().ofType(Double.class).defaultsTo(1.0);
      sgdClipGradients = parser.accepts("clipGradients", "Clip gradients to a max l2 norm of the given value.")
          .withRequiredArg().ofType(Double.class).defaultsTo(Double.MAX_VALUE);
      sgdAdagrad = parser.accepts("adagrad", "Use the adagrad algorithm for stochastic gradient descent.");
    }

    if (opts.contains(CommonOptions.LBFGS)) {
      lbfgs = parser.accepts("lbfgs");
      lbfgsIterations = parser.accepts("lbfgsIterations",
          "Maximum number of iterations (passes over the data) for LBFGS.").
          withRequiredArg().ofType(Integer.class).defaultsTo(100);
      lbfgsHessianRank = parser.accepts("lbfgsHessianRank",
          "Rank (number of vectors) of LBFGS's inverse Hessian approximation.")
          .withRequiredArg().ofType(Integer.class).defaultsTo(30);
      lbfgsL2Regularization = parser.accepts("lbfgsL2Regularization",
          "L2 regularization imposed by LBFGS")
          .withRequiredArg().ofType(Double.class).defaultsTo(0.0);

      // Providing either of these options triggers the use of minibatch LBFGS
      lbfgsMinibatchIterations = parser.accepts("lbfgsMinibatchIterations",
          "If specified, run LBFGS on minibatches of the data with the specified number of iterations per minibatch.")
          .withRequiredArg().ofType(Integer.class).defaultsTo(-1);
      lbfgsMinibatchSize = parser.accepts("lbfgsMinibatchSize",
          "If specified, run LBFGS on minibatches of the data with the specified number of examples per minibatch.")
          .withRequiredArg().ofType(Integer.class).defaultsTo(-1);

      lbfgsAdaptiveMinibatches = parser.accepts("lbfgsAdaptiveMinibatches",
          "If given, LBFGS is run on minibatches of exponentially increasing size.");
    }

    if (opts.contains(CommonOptions.STOCHASTIC_GRADIENT) || opts.contains(CommonOptions.LBFGS)) {
      logInterval = parser.accepts("logInterval",
          "Number of training iterations between logging outputs.")
          .withRequiredArg().ofType(Integer.class).defaultsTo(1);
      
      logParametersInterval = parser.accepts("logParametersInterval",
          "Number of training iterations between serializing parameters to disk during training. "
          + "If unspecified, model parameters are not serialized to disk during training.")
          .withRequiredArg().ofType(Integer.class).defaultsTo(-1);
      logParametersDir = parser.accepts("logParametersDir", "Directory where serialized model "
          + "parameters are stored. Must be specified if logParametersInterval is specified.")
          .withRequiredArg().ofType(String.class);

      logBrief = parser.accepts("logBrief", "Hides training output.");
    }

    if (opts.contains(CommonOptions.MAP_REDUCE)) {
      mrMaxThreads = parser.accepts("maxThreads",
          "Maximum number of threads to use during parallel execution.")
          .withRequiredArg().ofType(Integer.class).defaultsTo(Runtime.getRuntime().availableProcessors());
      mrMaxBatchesPerThread = parser.accepts("maxBatchesPerThread",
          "Number of batches of items to create per thread.")
          .withRequiredArg().ofType(Integer.class).defaultsTo(20);
    }

    if (opts.contains(CommonOptions.FUNCTIONAL_GRADIENT_ASCENT)) {
      fgaIterations = parser.accepts("fgaIterations",
          "Number of iterations of functional gradient ascent to perform.").withRequiredArg()
          .ofType(Integer.class).defaultsTo(10);
      fgaBatchSize = parser.accepts("fgaBatchSize",
          "Number of examples to process before each functional gradient update. If not provided, use the entire data set.")
          .withRequiredArg().ofType(Integer.class);
      fgaInitialStep = parser.accepts("fgaInitialStepSize",
          "Initial step size for functional gradient ascent.")
          .withRequiredArg().ofType(Double.class).defaultsTo(1.0);
      fgaNoDecayStepSize = parser.accepts("fgaNoDecayStepSize",
          "Don't use a 1/sqrt(t) step size decay during functional gradient ascent.");
    }

    if (opts.contains(CommonOptions.REGRESSION_TREE)) {
      rtreeMaxDepth = parser.accepts("rtreeMaxDepth", "Maximum depth of trained regression trees")
          .withRequiredArg().ofType(Integer.class).required();
    }
  }
777011
function Random(opts) {
    Readable.apply(this, arguments);

    if (opts && opts.objectMode) {
        this.objectMode = true;
    }

    this.dictionary = ['1', '0'];
}
1368223
def _init(init, X, N, rank, dtype):
    
    Uinit = [None for _ in range(N)]
    if isinstance(init, list):
        Uinit = init
    elif init == 'random':
        for n in range(1, N):
            Uinit[n] = array(rand(X.shape[n], rank), dtype=dtype)
    elif init == 'nvecs':
        for n in range(1, N):
            Uinit[n] = array(nvecs(X, n, rank), dtype=dtype)
    else:
        raise 'Unknown option (init=%s)' % str(init)
    return Uinit
1276407
def _spawn_new(self, count=1):
        """"""
        free = self.free_cells()
        for x, y in random.sample(free, min(count, len(free))):
            self.grid[y][x] = random.randint(0, 10) and 2 or 4
336796
def random_get_instance() -> tcod.random.Random:
    
    return tcod.random.Random._new_from_cdata(
        ffi.cast("mersenne_data_t*", lib.TCOD_random_get_instance())
    )
1107720
private void setUp(Random rand)
    {
        Ws = new ArrayList<>(npl.length);
        bs = new ArrayList<>(npl.length);
        
        //First Hiden layer takes input raw
        DenseMatrix W = new DenseMatrix(npl[0], inputSize);
        Vec b = new DenseVector(W.rows());
        initializeWeights(W, rand);
        initializeWeights(b, W.cols(), rand);
        Ws.add(W);
        bs.add(b);
        
        //Other Hiden Layers Layers 
        for(int i = 1; i < npl.length; i++)
        {
            W = new DenseMatrix(npl[i], npl[i-1]);
            b = new DenseVector(W.rows());
            initializeWeights(W, rand);
            initializeWeights(b, W.cols(), rand);
            Ws.add(W);
            bs.add(b);
        }
        
        //Output layer
        W = new DenseMatrix(outputSize, npl[npl.length-1]);
        b = new DenseVector(W.rows());
        initializeWeights(W, rand);
        initializeWeights(b, W.cols(), rand);
        Ws.add(W);
        bs.add(b);
        
    }
83929
def create_object(self, cls: Type[T], additional_kwargs=None) -> T:
        """"""
        additional_kwargs = additional_kwargs or {}
        log.debug('%sCreating %r object with %r', self._log_prefix, cls, additional_kwargs)

        try:
            instance = cls.__new__(cls)
        except TypeError as e:
            reraise(
                e,
                CallError(cls, getattr(cls.__new__, '__func__', cls.__new__), (), {}, e, self._stack),
                maximum_frames=2,
            )
        try:
            init = cls.__init__
            self.call_with_injection(init, self_=instance, kwargs=additional_kwargs)
        except TypeError as e:
            # The reason why getattr() fallback is used here is that
            # __init__.__func__ apparently doesn't exist for Key-type objects
            reraise(
                e,
                CallError(
                    instance,
                    getattr(instance.__init__, '__func__', instance.__init__),
                    (),
                    additional_kwargs,
                    e,
                    self._stack,
                ),
            )
        return instance
448620
def initialize(self):
        
        self.randomize()
        self.dweight = Numeric.zeros((self.fromLayer.size, \
                                      self.toLayer.size), 'f')
        self.wed = Numeric.zeros((self.fromLayer.size, \
                                  self.toLayer.size), 'f')
        self.wedLast = Numeric.zeros((self.fromLayer.size, \
                                      self.toLayer.size), 'f')
1063303
def generate_initialization_vector(words)
    srand(Time.now.to_i)
    vector = ""
    words.times {
      vector << [rand(ULONG)].pack('N')
    }
    return(vector)
  end
170310
def get_random_state(seed):
    
    if seed is None or seed is np.random:
        return np.random.mtrand._rand
    if isinstance(seed, (numbers.Integral, np.integer)):
        return np.random.RandomState(seed)
    if isinstance(seed, np.random.RandomState):
        return seed
    raise ValueError(
        '%r cannot be used to seed a np.random.RandomState instance' %
        seed)