random

How to generate 8 bytes unique random number in python?

自古美人都是妖i 提交于 2021-01-28 05:56:35
问题 Is there any way to generate a unique random number that has 8 bytes size in python language? I used the UUID library but it has 16 bytes which are not aligned with my requirement. Any help would be much appreciated. Thanks in advance 回答1: Well, you could use Linear Congruential Generator which, with proper selection of parameters, produce perfect mapping from u64 to u64. In other words, if you have access to previous 8bytes UUID, you could generate reasonable random next 8bytes UUID WITHOUT

Prolog: how to non-uniformly randomly select a element from a list?

佐手、 提交于 2021-01-28 05:53:53
问题 Does anyone have any Prolog code to non-uniformly select a random element from a list? I want to replicate the functionality of numpy.random.choice when given the probabilities associated with each entry in the input list. 回答1: I found nothing useful in library(random) . Here's my implementation choice(Xs, Ps, Y) : choice([X|_], [P|_], Cumul, Rand, X) :- Rand < Cumul + P. choice([_|Xs], [P|Ps], Cumul, Rand, Y) :- Cumul1 is Cumul + P, Rand >= Cumul1, choice(Xs, Ps, Cumul1, Rand, Y). choice([X]

Simulate from kernel density estimator with variable underlying grid

亡梦爱人 提交于 2021-01-28 05:51:02
问题 I have a dataset that I'm using to create an empirical probability distribution by estimating a kernel density. Right now I'm using R's kde2d from the MASS package. After estimating the probability distribution, I use sample to sample from slices of the 2D distribution along the x-axis. I use sample much like described here. Example code would look like this library(MASS) set.seed(123) x = rnorm(100, 1, 0.1) set.seed(456) y = rnorm(100, 1, 0.5) den <- kde2d(x, y, n = 50, lims = c(-2, 2, -2, 2

Why does numpy.random.choice not use arithmetic coding?

做~自己de王妃 提交于 2021-01-28 05:46:00
问题 If I evaluate something like: numpy.random.choice(2, size=100000, p=[0.01, 0.99]) using one uniformly-distributed random float , say r , and deciding if r < 0.01 will presumably waste many of the random bits (entropy) generated. I've heard (second-hand) that generating psuedo-random numbers is computationally expensive, so I assumed that numpy would not be doing that, and rather would use a scheme like arithmetic coding in this case. However, at first glance it appears that choice does indeed

Monte Carlo simulations in Python using quasi random standard normal numbers using sobol sequences gives erroneous values

感情迁移 提交于 2021-01-28 05:10:06
问题 I'm trying to perform Monte Carlo Simulations using quasi-random standard normal numbers. I understand that we can use Sobol sequences to generate uniform numbers, and then use probability integral transform to convert them to standard normal numbers. My code gives unrealistic values of the simulated asset path: import sobol_seq import numpy as np from scipy.stats import norm def i4_sobol_generate_std_normal(dim_num, n, skip=1): """ Generates multivariate standard normal quasi-random

Change the random number generator in Matlab function

偶尔善良 提交于 2021-01-28 04:03:05
问题 I have a task to complete that requires quasi-random numbers as input, but I notice that the Matlab function I want to use does not have an option to select any of the quasi generators I want to use (e.g. Halton, Sobol, etc.). Matlab has them as stand alone functions and not as options in the ubiquitous 'randn' and 'rng' functions. What MatLab uses is the Mersenne Twister, a pseudo generator. So for instance the copularnd uses 'randn'/'rng' which is based on pseudo random numbers.... Is there

Script for Selecting random data from a list on button press

ⅰ亾dé卋堺 提交于 2021-01-28 02:34:53
问题 I'm creating a spreadsheet which can automatically select random cell data from a particular column when I press a button. However, I cannot figure out the script. Thanks to some friends I've tried a few variations that involve using add-ons but ideally I don't want to use anything like that as it needs to be usable if people wanted to make a copy without the addons. What I'm looking to do is click a particular button and then the adjacent cell displays a random value from the data set given

Impact of setting random.seed() to recreate a simulated behaviour and choosing the seed

ⅰ亾dé卋堺 提交于 2021-01-28 01:50:29
问题 I am doing a scheduling simulation in python which is full determinstic. So, when I have the same input and parameters I always get the same output. Now I want to randomize the initial starting state of the simulation and compare the output of two (or more) different simulation parameters. To compare the "same randomized initial starting state" I want to set the random.seed() with an initial value, which should stay the same for all comparisions of different schedulers. Furthermore I want to

Fill an array with distanced random integers

我是研究僧i 提交于 2021-01-28 01:20:56
问题 I need an array to be filled with random integers Those integers should be very distinct from each other i.e. must at least be 20 units of separation between each items This is what i have tried so far : var all = []; var i = 0; randomDiff(); function randomDiff() { var num1 = randomNumber(10, 290); //chose a first random num in the range... all[0] = num1; //...put it in first index of array do // until you have 12 items... { var temp = randomNumber(10, 290); //...you pick a temporary num var

How to calculate mean, mode, variance, standard deviation etc. of output in python?

末鹿安然 提交于 2021-01-27 21:50:43
问题 I have a simple game which is based on probabilities, every day we toss a coin and if we get heads then we win and we get $20 and if we toss the coin and we get tails then we lose $19, at the end of the month (28 days) we see how much we have lost or made. def coin_tossing_game(): random_numbers = [random.randint(0, 1) for x in range(500)] #generate 500 random numbers for x in random_numbers: if x == 0: #if we get heads return 20 #we win $20 elif x == 1: #if we get tails return -19 #we lose