random

How would you keep a Math.random() in javascript from picking the same numbers multiple times?

I have an array var words = []//lots of different words in it. I have a Math.floor(Math.random()*words.length) that chooses a random word from the array. This is run in a loop that runs for a random number of times (between 2 and 200 times). I would like to make sure that the random numbers do not get chosen more than once during the tim...

How to generate a random partition from an iterator in Python

Given the desired number of partitions, the partitions should be nearly equal in size. This question handles the problem for a list. They do not have the random property, but that is easily added. My problem is, that I have an iterator as input, so shuffle does not apply. The reason for that is that I want to randomly partition the nodes...

sources of "uniqueness"/entropy on embedded systems

I have an embedded system. What I would like for it to do when it powers up or otherwise resets, is to generate a unique ID, so that on different restarts a different unique ID is generated with high probability. It does not have access to a real-time clock, but it does have access to an ADC and a UART. I am wondering if there is a dece...

Haskell Random from Datatype

Hi all, Im pretty new to Haskell. I have a datatype: data Sentence= Prop Int | No Sentence | And [Sentence] | Or [Sentence] deriving Eq I already wrote a Show instance for it However, whether it makes sense or not, I would like to be able to generate a random Sentence. How can i accomplish this...

How do I load a random document from CouchDB (efficiently and fairly)?

I would like to load a random document out of a set of documents stored in a CouchDB database. The method for picking and loading the document should conform to the following requirements: Efficiency: The lookup of the document should be efficient, most importantly the time to load the document must not grow linearly with the total num...

write a c function that generates one random number, or a pair of random numbers, or a triplet of random numbers given the particular ranges.

i have to generate random numbers for 3 different cases. i. 1 dice ii. a pair of dice iii. 3 dices my questions: 1. please suggest me sm good logic to generate random numbers for all the 3 cases. 2. does the logic change when i consider the cses of 2 dices, rather than 1? 3.how much of an effect does the range in which we have to genrate...

MySQL Select by random.

I have a list of items for businesses in a database: listings `id` `location` `item` `status` So in the database I might have something like: 19 Loc A Green Beans for $12 active 20 Loc B Two Gatoraids for $3 deactive 21 Loc A Ham for $2 per lb active 22 Loc A Pepsi 2 for $2 active 23 Loc C House pla...

Random number help in Objective-C?

I would like to create just one random number but instead a new random number is being made every time the button is clicked. Where should i put the random number declaration so that it only creates one random number? ...

How can you select a random element from a list, and have it be removed?

Let's say I have a list of colours, colours = ['red', 'blue', 'green', 'purple']. I then wish to call this python function that I hope exists, random_object = random_choice(colours). Now, if random_object holds 'blue', I hope colours = ['red', 'green', 'purple']. Does such a function exist in python? ...

Trouble with C# Random class

Hey guys, I've got a class that represents a coin, which can be flipped with the Coin.Flip() method. Flip() uses random.Next(2); to get either a 0 or a 1 representing heads or tails. This works good.. sort of. For the program, I need to have 2 coins, which I make, lets say coin1 and coin2. coin2 always needs to be flipped straight aft...

Random Number Generator not working

I use this function to create random numbers between 100000000 and 999999999 int irand(int start, int stop) { double range = stop - start + 1; return start + (int)(range * rand()/(RAND_MAX+1.0)); } When I use it like this, it's properly working while(1) { DWORD dw = irand(100000000, 999999999); printf("dynamic key: %d\n",...

generating a batch of random passwords

Generating a random password is easy. but generating a batch is more difficult. public static string getRandomPassword(int letters, int getallen) { //int letters = 8; //int getallen = 5; char[] letterdeel = new char[letters]; int minGetal = (int)Math.Pow(10, getallen - 1); int maxGetal = (int...

Does Repeating a Biased Random Shuffle Reduce the Bias?

I'd like to produce fast random shuffles repeatedly with minimal bias. It's known that the Fisher-Yates shuffle is unbiased as long as the underlying random number generator (RNG) is unbiased. To shuffle an array a of n elements: for i from n − 1 downto 1 do j ← random integer with 0 ≤ j ≤ i exchange a[j] and a[i] But...

What could be causing a deadlock or otherwise causing this concurrency test to inconsistently fail?

I've been fiddling around with CHESS, which seems like an incredibly useful tool. However, ironically, I seem to be dealing with a Heisenbug in one of my test methods. The results reported by CHESS when I run this test are unpredictable: Sometimes the test will pass Sometimes the test will fail, with no further description (simply: "Te...

Random text from MySQL with button click and no refresh with PHP

Hi, I was wondering if someone could point me in the right direction for this: I have a MySQL database with and id and a text string, i want to be able to display it, and with the click of a button display another random phrase without having to refresh the whole page. I have look quite thoroughly and have no found no answer for this ...

Generating totally random numbers without random function?

Possible Duplicate: True random number generator I was talking to a friend the other day and we were trying to figure out if it is possible to generate completely random numbers without the help of a random function? In C for example "rand" generates pseudo-random numbers. Or we can use something like "srand( time( NULL ) );...

Is C still relevant?

It's all in the title. ...

Random natural movement jquery

Hi, How can I recreate this type movement with jquery for images: http://www.istockphoto.com/stock-video-12805249-moving-particles-loop-soft-green-hd-1080.php I'm planning to use it as a web page background. If it is not possible with jquery I'll go with flash as3. But I prefer jquery. ...

c# forms: where do i place my random number generator?

Hey guys, I was trying to use a random number generator in a windows forms app, but I'm having trouble figuring out where to put it. I'm being told "place it in the form constructor" but I don't think we're talking the same language. Here's the code im trying to find a home for: Random rnd = new Random(); int guessMe = rnd.Next(0,100);...

Choosing N random numbers from a set

I have a sorted set (std::set to be precise) that contains elements with an assigned weight. I want to randomly choose N elements from this set, while the elements with higher weight should have a bigger probability of being chosen. Any element can be chosen multiple times. I want to do this as efficiently as possible - I want to avoid ...