random

Javascript: Generate random numbers with fixed mean and standard deviation

末鹿安然 提交于 2020-07-17 10:07:40
问题 My question: How can I create a list of random numbers with a given mean and standard deviation (sd) in Javascript? Example: I want to create a list with 5 random numbers in a range between 1 to 10. The resulting mean should be 5 and the standard deviation should be 2. What I've done so far: My idea was (http://jsfiddle.net/QASDG/3/): Make a function (named "createData") which creates 5 random numbers between 1 and 10 and push them into an "array" This function should also calculate the mean

Javascript: Generate random numbers with fixed mean and standard deviation

自作多情 提交于 2020-07-17 10:05:05
问题 My question: How can I create a list of random numbers with a given mean and standard deviation (sd) in Javascript? Example: I want to create a list with 5 random numbers in a range between 1 to 10. The resulting mean should be 5 and the standard deviation should be 2. What I've done so far: My idea was (http://jsfiddle.net/QASDG/3/): Make a function (named "createData") which creates 5 random numbers between 1 and 10 and push them into an "array" This function should also calculate the mean

Shuffle output of find with fixed seed

亡梦爱人 提交于 2020-07-15 15:19:50
问题 I would like to shuffle output of find BUT with a fixed seed, so that every time I run the command I get the same output. Here's how I shuffle: find . -name '*.wav' | shuf The issue is that every time we have a new seed -> new order. My attempt to fix it: find . -name '*.wav' | shuf --random-source=<(echo 42) That works only on occasions (i.e. just a few cases, in a deterministic way). Most of the time it fails with: shuf: ‘/proc/self/fd/12’: end of file Same error is produced by e.g. seq 1

Random without repetition in Python

99封情书 提交于 2020-07-13 15:49:14
问题 I want to write a program that displays all the elements of a list in random order without repetition. It seems to me that it should work, but only prints those elements with repetition. import random tab = [] for i in range(1, 8): item = random.choice(["house", "word", "computer", "table", "cat", "enter", "space"]) if item not in tab: print(item) else: tab.append(item) continue 回答1: Instead of random.choice within the for loop, use random.shuffle here. This way, your list is guaranteed to be

Random without repetition in Python

让人想犯罪 __ 提交于 2020-07-13 15:49:11
问题 I want to write a program that displays all the elements of a list in random order without repetition. It seems to me that it should work, but only prints those elements with repetition. import random tab = [] for i in range(1, 8): item = random.choice(["house", "word", "computer", "table", "cat", "enter", "space"]) if item not in tab: print(item) else: tab.append(item) continue 回答1: Instead of random.choice within the for loop, use random.shuffle here. This way, your list is guaranteed to be

Random without repetition in Python

佐手、 提交于 2020-07-13 15:47:53
问题 I want to write a program that displays all the elements of a list in random order without repetition. It seems to me that it should work, but only prints those elements with repetition. import random tab = [] for i in range(1, 8): item = random.choice(["house", "word", "computer", "table", "cat", "enter", "space"]) if item not in tab: print(item) else: tab.append(item) continue 回答1: Instead of random.choice within the for loop, use random.shuffle here. This way, your list is guaranteed to be

Random without repetition in Python

℡╲_俬逩灬. 提交于 2020-07-13 15:46:55
问题 I want to write a program that displays all the elements of a list in random order without repetition. It seems to me that it should work, but only prints those elements with repetition. import random tab = [] for i in range(1, 8): item = random.choice(["house", "word", "computer", "table", "cat", "enter", "space"]) if item not in tab: print(item) else: tab.append(item) continue 回答1: Instead of random.choice within the for loop, use random.shuffle here. This way, your list is guaranteed to be

Generate a random number from 0 to 10000000

别来无恙 提交于 2020-07-11 05:43:30
问题 How can I generate random numbers from 0 to 1000000? I already tried the code below, but it still gives me numbers from 0 to 32767 (RAND_MAX): #include <stdio.h> #include <stdlib.h> #include <time.h> int main(){ int i,x; srand(time(NULL)); for(i=0; i<10000; i++){ int x = rand() % 10000000 + 1; printf("%d\n",x); } return 0; } 回答1: [Edit] The initial answer was for 0 to 1,000,000. I now see it should be 0 to 10,000,000. As rand() will give an answer of at least 15 bits, call rand() multiple

Generate a random number from 0 to 10000000

馋奶兔 提交于 2020-07-11 05:42:12
问题 How can I generate random numbers from 0 to 1000000? I already tried the code below, but it still gives me numbers from 0 to 32767 (RAND_MAX): #include <stdio.h> #include <stdlib.h> #include <time.h> int main(){ int i,x; srand(time(NULL)); for(i=0; i<10000; i++){ int x = rand() % 10000000 + 1; printf("%d\n",x); } return 0; } 回答1: [Edit] The initial answer was for 0 to 1,000,000. I now see it should be 0 to 10,000,000. As rand() will give an answer of at least 15 bits, call rand() multiple

Why does numpy.random.Generator.choice provides different results (seeded) with given uniform distribution compared to default uniform distribution?

前提是你 提交于 2020-07-10 10:27:05
问题 Simple test code: pop = numpy.arange(20) rng = numpy.random.default_rng(1) rng.choice(pop,p=numpy.repeat(1/len(pop),len(pop))) # yields 10 rng = numpy.random.default_rng(1) rng.choice(pop) # yields 9 The numpy documentation says: The probabilities associated with each entry in a. If not given the sample assumes a uniform distribution over all entries in a. I don't know of any other way to create a uniform distribution, but numpy.repeat(1/len(pop),len(pop)) . Is numpy using something else? Why