random-sample

Each simulation of normal distribution is the same (C++)

老子叫甜甜 提交于 2019-12-23 05:28:13
问题 I write a code to simulate a normal distribution in C++. But each time it seems the result is the same. My question is what't the reason of this phenomenon and How to fix it? I never have this problem with Python. Any references are very appreciated. // Simulation.cpp : Defines the entry point for the console application. #include "stdafx.h" #include <iostream> #include<random> void main(){ // create default engine as source of randomness // The maxtime we do expriements is 10000 // Record to

Storing the results of a prepared statement as a table in mysql?

江枫思渺然 提交于 2019-12-22 08:25:15
问题 Is it possible to store the result of a prepared table in mysql ? My use case is - : I am creating two variables based on certain conditions of the source table, then fetching the randomized rows, based on this criteria. Since I have 10 of such tables, should I be 1st joining them and then doing this randomization on the "overall" passing/filtering criteria (See also @total below, which is my main criteria, PER table) set @total=(select count(*) from tab_1 where predict_var ="4" or predict

Can `rand()` in c++ be used to generate unbiased bools?

人盡茶涼 提交于 2019-12-22 06:28:08
问题 I have written the following function bool random_bool(double probability) { double p_scaled = probability * (RAND_MAX+1) - rand(); if ( p_scaled >= 1 ) return true; if ( p_scaled <= 0 ) return false; return random_bool( p_scaled ); } Given, that rand() generates a number from uniform distribution on {0,1,...,RAND_MAX-1,RAND_MAX} and numbers from subsequent calls can be treated as independent for all practical purposes except cryptography, this should return true with probability p : two if

Can `rand()` in c++ be used to generate unbiased bools?

时间秒杀一切 提交于 2019-12-22 06:28:05
问题 I have written the following function bool random_bool(double probability) { double p_scaled = probability * (RAND_MAX+1) - rand(); if ( p_scaled >= 1 ) return true; if ( p_scaled <= 0 ) return false; return random_bool( p_scaled ); } Given, that rand() generates a number from uniform distribution on {0,1,...,RAND_MAX-1,RAND_MAX} and numbers from subsequent calls can be treated as independent for all practical purposes except cryptography, this should return true with probability p : two if

Generating random numbers on open-open interval (0,1) efficiently

可紊 提交于 2019-12-21 17:00:10
问题 I'm looking for an efficient way to generate random floating-point numbers on the open-open interval (0,1). I currently have an RNG that generates random integers on the closed-closed interval of [0, (2^32)-1]. I've already created a half-open floating point RNG on the interval [0,1) by simply multiplying my result from the integer RNG by 1/((2^32)-1) rather than dividing by (2^32)-1 since it's inefficient. The way I'm currently going about generating numbers on the interval (0,1) is with a

R-How to generate random sample of a discrete random variables?

假如想象 提交于 2019-12-21 07:26:46
问题 In R, I want to generate a random sample of a discrete random variable: X , where: P(X=a)=P(X=-a)=1/2 . I have been searching for a function online, but there seems no direct function doing this. 回答1: I think you are looking to generate samples of a Bernoulli random variable. A Bernoulli random variable is a special case of a binomial random variable. Therefore, you can try rbinom(N,1,p) . This will generate N samples, with value 1 with probability p , value 0 with probability (1-p) . To get

pandas create a series with n elements (sequential or randbetween)

流过昼夜 提交于 2019-12-18 22:32:04
问题 I am trying to create a pandas series. One column of the series should contain n sequential numbers. [1, 2, 3, ..., n] One column should contain random numbers between k and k+100 . One column should contain random selection between strings in a list. ['A', 'B', 'C', ... 'Z'] 回答1: There can be a lot of solutions. In the comments of the code block ( # ) you will find a few links for more information: import pandas as pd import numpy as np import random import string k = 5 N = 10 #http://docs

Generating Random Date time in java (joda time)

↘锁芯ラ 提交于 2019-12-18 21:54:13
问题 Is it possible to generate a random datetime using Jodatime such that the datetime has the format yyyy-MM-dd HH:MM:SS and it should be able to generate two random datetimes where Date2 minus Date1 will be greater than 2 minutes but less than 60minutes. Please suggest some method. 回答1: This follows quite strictly what you asked for (except for the corrected format). Random random = new Random(); DateTime startTime = new DateTime(random.nextLong()).withMillisOfSecond(0); Minutes minimumPeriod =

Select n records at random from a set of N

主宰稳场 提交于 2019-12-18 06:57:49
问题 I need to select n records at random from a set of N (where 0 < n < N ). A possible algorithm is: Iterate through the list and for each element, make the probability of selection = (number needed) / (number left) So if you had 40 items, the first would have a 5/40 chance of being selected. If it is, the next has a 4/39 chance, otherwise it has a 5/39 chance. By the time you get to the end you will have your 5 items, and often you'll have all of them before that. Assuming a good pseudo-random

Sampling from Oracle, Need exact number of results (Sample Clause)

时光总嘲笑我的痴心妄想 提交于 2019-12-18 06:24:52
问题 I am trying to pull a random sample of a population from a Peoplesoft Database. The searches online have lead me to think that the Sample Clause of the select statement may be a viable option for us to use, however I am having trouble understanding how the Sample clause determines the number of samples returned. I have looked at the oracle documentation found here: http://docs.oracle.com/cd/E11882_01/server.112/e26088/statements_10002.htm#i2065953 But the above reference only talks about the