random

Using if conditions inside a TensorFlow graph

南楼画角 提交于 2020-01-11 03:58:15
问题 In tensorflow CIFAR-10 tutorial in cifar10_inputs.py line 174 it is said you should randomize the order of the operations random_contrast and random_brightness for better data augmentation. To do so the first thing I think of is drawing a random variable from the uniform distribution between 0 and 1 : p_order. And do: if p_order>0.5: distorted_image=tf.image.random_contrast(image) distorted_image=tf.image.random_brightness(distorted_image) else: distorted_image=tf.image.random_brightness

How to generate a random number with Java from given list of numbers

青春壹個敷衍的年華 提交于 2020-01-11 03:35:06
问题 Assume I have an array/vector of numbers like 1,3,7,9 then I need to guess a number from this list randomly. Using Random class in Java it seems like not possible to do this. Could anyone kindly help me to tell a way to do this kind of thing. I have to change the list of numbers used to generate random number. I am trying to implement a strategy to play battleship game automatically as an assignment. Kindly help me to do this ? 回答1: Put the numbers in an ArrayList and use Collections.shuffle

is it possible to find random floats in range [a,b] in python?

╄→尐↘猪︶ㄣ 提交于 2020-01-11 03:32:08
问题 I'm trying to generate in python random floats in the range of [0.8,0.9] , but unfortanetly all the tools i found could only generate randoms in the range of [a,b) for floats. ( like Random.uniform(a,b) ) Meanwhile , I tried doing something like this : uniform(0.8,0.90000000001) but thats realy bad any ideas ? 回答1: The difference between [0.8, 0.9] and [0.8,0.9) is vanishingly small. Given the limitations of binary floating-point, I don't think there even is a difference, since 0.9 can't be

How does one seed the random number generator in Swift?

大兔子大兔子 提交于 2020-01-11 02:57:20
问题 My app uses random numbers. I would like to seed the random number generator so that it won't be the same every time. How might I go about doing this? EDIT: What parameter do I give srand() to seed the random generator with the current time? 回答1: This works: let time = UInt32(NSDate().timeIntervalSinceReferenceDate) srand(time) print("Random number: \(rand()%10)") 来源: https://stackoverflow.com/questions/25895081/how-does-one-seed-the-random-number-generator-in-swift

Simulate from an (arbitrary) continuous probability distribution [duplicate]

核能气质少年 提交于 2020-01-10 20:13:14
问题 This question already has answers here : How do I best simulate an arbitrary univariate random variate using its probability function? (4 answers) Closed 5 years ago . For a normalized probability density function defined on the real line, for example p(x) = (2/pi) * (1/(exp(x)+exp(-x)) (this is just an example; the solution should apply for any continuous PDF we can define) is there a package in R to simulate from the distribution? I am aware of R's built-in simulators for many distributions

How to randomize enum elements? [duplicate]

谁都会走 提交于 2020-01-10 14:12:28
问题 This question already has answers here : Pick a random value from an enum? (12 answers) Closed 4 years ago . Say you have an enum with some elements public enum LightColor { RED, YELLOW, GREEN } And would like to randomly pick any color from it. I put colors into a public List<LightColor> lightColorChoices = new ArrayList<LightColor>(); lightColorChoices.add(LightColor.GREEN); lightColorChoices.add(LightColor.YELLOW); lightColorChoices.add(LightColor.RED); And then picked a random color like:

How to randomize enum elements? [duplicate]

坚强是说给别人听的谎言 提交于 2020-01-10 14:12:17
问题 This question already has answers here : Pick a random value from an enum? (12 answers) Closed 4 years ago . Say you have an enum with some elements public enum LightColor { RED, YELLOW, GREEN } And would like to randomly pick any color from it. I put colors into a public List<LightColor> lightColorChoices = new ArrayList<LightColor>(); lightColorChoices.add(LightColor.GREEN); lightColorChoices.add(LightColor.YELLOW); lightColorChoices.add(LightColor.RED); And then picked a random color like:

Efficiently generating unique pairs of integers

北慕城南 提交于 2020-01-10 10:16:05
问题 In MATLAB, I would like to generate n pairs of random integers in the range [1, m] , where each pair is unique. For uniqueness, I consider the order of the numbers in the pair to be irrelevant such that [3, 10] is equal to [10, 3] . Also, each pair should consist of two distinct integers; i.e. [3, 4] is ok but [3, 3] would be rejected. EDIT: Each possible pair should be chosen with equal likelihood. (Obviously a constraint on the parameters is that n <= m(m-1)/2 .) I have been able to

Do std::random_device and std::mt19937 follow an uniform distribution?

安稳与你 提交于 2020-01-10 05:22:07
问题 I'm trying to convert this line of matlab in C++: rp = randperm(p); Following the randperm documentation: randperm uses the same random number generator as rand And in rand page: rand returns a single uniformly distributed random number So rand follows an uniform distribution. My C++ code is based on: std::random_device rd; std::mt19937 g(rd()); std::shuffle(... , ... ,g); My question is: the code above follows an uniform distribution? If not, how to do so? 回答1: The different classes from the

Faster than rand()?

…衆ロ難τιáo~ 提交于 2020-01-10 04:12:12
问题 I'm working on an algorithm which needs to generate millions of numbers as fast as possible. Actually I found out that the rand() function of my algorithm takes 75% of the process time. So I'm looking for something faster. And I don't need a big range at all. (I only need integer numbers below 1000) Do you know something I could use ? Thanks ! Edit : I use this numbers for shuffling groups of less than 1000 entities. I found out more about the "fast rand". And there is SSE version version