random

How can the RNGCryptoServiceProvider be used to generate Bridge hands?

倖福魔咒の 提交于 2020-01-02 05:43:08
问题 The game of Bridge is played with 52 different playing cards that are randomly distributed among four players, each player ending up with thirteen cards: a so called "deal". Roughly a little less than 2^96 Bridge deals are possible. In this document the requirements for a program that generates random deals are described as follows: The software should be able to generate every possible bridge deal, since that is also possible with manual dealing. The software should generate every deal with

Random number generator that fills an interval

大憨熊 提交于 2020-01-02 05:31:26
问题 How would you implement a random number generator that, given an interval, (randomly) generates all numbers in that interval, without any repetition? It should consume as little time and memory as possible. Example in a just-invented C#-ruby-ish pseudocode: interval = new Interval(0,9) rg = new RandomGenerator(interval); count = interval.Count // equals 10 count.times.do{ print rg.GetNext() + " " } This should output something like : 1 4 3 2 7 5 0 9 8 6 回答1: Fill an array with the interval,

Update column with random value

会有一股神秘感。 提交于 2020-01-02 04:43:05
问题 I have a table: ID | VALUE | DATE 1 | 5 | 2012-10-01 2 | 7 | 2012-10-02 3 | 3 | 2012-10-05 4 | 0 | 2012-05-07 I want to add on the top of the current value with the VALUE random individually BETWEEN 1 AND 5. Let say: ID | VALUE | RANDOM VALUE 1 | 5 | 0 2 | 7 | 2 3 | 3 | 3 4 | 0 | 6 NEW VALUE ID | VALUE 1 | 5 2 | 9 3 | 6 4 | 6 How do I do this? All I can think of is by doing cursor type of query. Any help? 回答1: Try UPDATE TABLE SET VALUE=VALUE+ROUND(1+RAND()*4); 回答2: This will update the value

Cycle of SecureRandom of Java

ぃ、小莉子 提交于 2020-01-02 04:36:06
问题 PRNGs usually have a cycle after which the generated random numbers do repeat. What's the cycle of SecureRandom of Java when the instance of SecureRandom is created as follows: SecureRandom random = SecureRandom.getInstance("SHA1PRNG"); 回答1: I'm a bit confused. I had a look into the code of sun.security.provider.SecureRandom of the openjdk. Here the internal state is updated as follows: digest.update(state); output = digest.digest(); updateState(state, output); [...] private static void

generate random string

拟墨画扇 提交于 2020-01-02 04:13:48
问题 well i know that there are a lot of these threads but im new to vb.net yet i cant edit the sources given to make what i really want so i want a function that will generate random strings which will contain from 15-32 characters each and each of them will have the following chars ( not all at the same string but some of them ) : A-Z a-z 0-9 here is my code so far Functon RandomString() Dim s As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" Dim r As New Random Dim sb As New StringBuilder For

Python: Selecting numbers with associated probabilities [duplicate]

南楼画角 提交于 2020-01-02 04:10:12
问题 This question already has answers here : Closed 9 years ago . Possible Duplicates: Random weighted choice Generate random numbers with a given (numerical) distribution I have a list of list which contains a series on numbers and there associated probabilities. prob_list = [[1, 0.5], [2, 0.25], [3, 0.05], [4, 0.01], [5, 0.09], [6, 0.1]] for example in prob_list[0] the number 1 has a probability of 0.5 associated with it. So you would expect 1 to show up 50% of the time. How do I add weight to

Getting random numbers in a thread-safe way

岁酱吖の 提交于 2020-01-02 02:56:13
问题 Here is a nice article describing thread safety of random numbers:Getting random numbers in a thread-safe way But I'm stuck with the "RandomGen2" example: public static class RandomGen2 { private static Random _global = new Random(); [ThreadStatic] private static Random _local; public static int Next() { Random inst = _local; if (inst == null) { int seed; lock (_global) seed = _global.Next(); _local = inst = new Random(seed); } return inst.Next(); } } Why is the thread static field copied to

Given a RNG algorithm and a series of numbers is it possible to determine what seed would produce the series?

限于喜欢 提交于 2020-01-02 02:24:10
问题 The code is in Objective C but it should be understandable if you look it over even if you don't know Objective C. Basically its a RNG object, you instantiate a new instance, set the seed if you want and start grabbing random numbers. So is it possible to backtrack a given series of numbers to determine the seed used to generate the numbers? I'm guessing any given algorithm can't generate just any random set of numbers though, or can it? Say I do the following: rng.seed = 1024; for (int i=1;

Which algorithm used by the rnorm function

送分小仙女□ 提交于 2020-01-02 01:01:09
问题 Which algorithm is using by the rnorm function by default to generate standard-normally distributed random numbers? 回答1: See ?RNGkind . The default is an inversion algorithm: normal.kind can be "Kinderman-Ramage", "Buggy Kinderman-Ramage" (not for set.seed ), "Ahrens-Dieter", "Box-Muller", "Inversion" (the default), or "user-supplied". (For inversion, see the reference in qnorm .) The Kinderman-Ramage generator used in versions prior to 1.7.1 (now called "Buggy") had several approximation

Scala: Random List of Val Order

心不动则不痛 提交于 2020-01-01 20:01:06
问题 I have some of val that should randomly coming to list of result. Here's the code: def motivation(name:String, score:Int){ val quote1 = "You're not lost. You're locationally challenged." //score=10 val quote2 = "Time is the most valuable thing a man can spend." //score=20 val quote3 = "At times one remains faithful to a cause." //score=10 val quote4 = "Only because its opponents do not cease to be insipid." //score=10 val quote5 = "Life can be complicated." //score=20 case Some(score) => val