random

generate a 2D array of numpy.random.choice without replacement

痞子三分冷 提交于 2021-02-08 03:38:34
问题 I'm tyring to make my code faster by removing some for loops and using arrays. The slowest step right now is the generation of the random lists. context: I have a number of mutations in a chromosome, i want to perform 1000 random "chromosomes" with the same length and same number of mutation but their positions are randomized. here is what I'm currently running to generate these randomized mutation positions: iterations=1000 Chr_size=1000000 num_mut=500 randbps=[] for k in range(iterations):

random function in C++

╄→гoц情女王★ 提交于 2021-02-08 02:56:52
问题 Is there a function that generates k random numbers within a specified range. For example I want 5 random numbers between 0 to 100, with or without replacement. 回答1: You could use std::generate_n with either rand() or a generator from the new C++11 random number generators. 回答2: There is the Boost library, which you can use to generate random numbers, for example. The following code generates 5 random numbers from [0, 100] with replacement : #include <vector> #include <boost/random/mersenne

How can I get the seed from a Random already created

早过忘川 提交于 2021-02-07 23:15:04
问题 I have to be able to repeat an experiment made with my code, it makes a few random numbers and I need to get the initialization value of my new random() sentence. I have this sentence to make the random object I use Dim r As Random = New Random() As I have read it gets the initialization value from system datetime. If the experiment were successfull I'd needed to be able to repeat it. How could I get the initialization number to be able to do: Dim r As Random = New Random

How can I get the seed from a Random already created

£可爱£侵袭症+ 提交于 2021-02-07 23:14:03
问题 I have to be able to repeat an experiment made with my code, it makes a few random numbers and I need to get the initialization value of my new random() sentence. I have this sentence to make the random object I use Dim r As Random = New Random() As I have read it gets the initialization value from system datetime. If the experiment were successfull I'd needed to be able to repeat it. How could I get the initialization number to be able to do: Dim r As Random = New Random

ValueError: Sample larger than population selecting samples from graph

自作多情 提交于 2021-02-07 18:43:21
问题 I am trying to randomly select n samples from a graph. In order to do so I create a list called X using the random.sample function like the following: X= random.sample(range(graph.ecount()), numPosSamples) The problem is that when numPosSamples is equal to graph.ecount() I receive the following error: ValueError: Sample larger than population Any help will be much appreciated. Thanks 回答1: I'm not sure how numPosSamples is getting its value, but because random.sample does sampling without

Swift Array - Difference between “Int.random(in: 0…25)” and “randomElement()”

南楼画角 提交于 2021-02-07 17:25:30
问题 I recently started learning swift via an online course. I was given the Task to generate a passwort out of a given Array containing characters. We learned mainly two code examples to randomly choose one. variable[Int.random(in: 0...25)] variable.randomElement() Both work just fine when pulling out one single element out of an array but only " variable[Int.random(in: 0...25) " when combined multiple times with a plus (+). Why is that? I looked up the documentation but couldn't find an answer

How To Set Global Random Seed in Python

北慕城南 提交于 2021-02-07 17:13:31
问题 Like in R, I would like to set a random seed globally for the entire script/session, instead of having to call the random seed function every time I execute a function or run a model. I am aware that sci-kit learn uses the numpy RNG, but also could not find a way to set it globally. I have read several posts here on this topic, such as this one: Differences between numpy.random and random.random in Python It explains the difference between the two RNG classes, but not how to set it globally.

Why is Int.random() slower than arc4random_uniform()?

依然范特西╮ 提交于 2021-02-07 14:16:55
问题 I have used Int.random() method and arc4random_uniform() for number generation speed tests. Both tests were run in macOS console with build configuration set to release. Below are codes which I have used for testing. public func randomGen1() { let n = 1_000_000 let startTime = CFAbsoluteTimeGetCurrent() for i in 0..<n { _ = arc4random_uniform(10) } let timeElapsed = CFAbsoluteTimeGetCurrent() - startTime print(timeElapsed) } public func randomGen2() { let n = 1_000_000 let startTime =

Random but most likely 1 float

北城以北 提交于 2021-02-07 12:37:46
问题 I want to randomize a float that so that There is 95% chance to be about 1 There is 0.01% chance to be < 0.1 or > 1.9 It never becomes 0 or 2 Is this possible by using Random.nextFloat() several times for example? A visual illustration of the probability: 回答1: You need to find a function f such that: f is continuous and increasing on [0, 1] f(0) > 0 and f(1) < 2 f(0.01) >= 0.1 and f(0.99) <= 1.9 f(x) is "about 1" for 0.025 <= x <= 0.975 And then just take f(Random.nextDouble()) For example,

Random number: 0 or 1

天大地大妈咪最大 提交于 2021-02-07 11:16:14
问题 Am I looking too far to see something as simple as pick a number: 0 or 1? Random rand = new Random(); if (rand.NextDouble() == 0) { lnkEvents.CssClass = "selected"; } else { lnkNews.CssClass = "selected"; } 回答1: Random rand = new Random(); if (rand.Next(0, 2) == 0) lnkEvents.CssClass = "selected"; else lnkNews.CssClass = "selected"; Random.Next picks a random integer between the lower bound (inclusive) and the upper bound (exclusive). 回答2: If you want 50/50 probability, I suggest: Random rand