random

Distributed random on cluster

I need a deterministic random number generator that maintains some sort of distribution (e.g. uniform or normal) that works over a cluster. Boost::Random fulfils most of these requirements. Is there any way I can use it in a cluster while maintaining the distribution? If there was an efficent way to advance the the number generator thi...

Postgis random point inside a polygon

Hello all If i have a polygon in Postgis how can i find-calculate random points inside this polygon? ...

Algorithm for picking thumbed-up items

I have a Pandora-like piece of software where the user can thumb up a song or thumb down a song. The software, called Chavah, is Silverlight + C#, but this is a language- and platform-neutral question. My software needs to choose a song based on the user's preferences. I need a good algorithm for this. I want my software to choose a so...

Solaris dev/random

Hallo, Which algorithm implements dev/random of Solaris? Is taht Yarrow-160 or Yarrow-256 or is the algorithm the same as in Linux? Is there documentation / link ? I have already looked a lot, but I couldn't find it. Thanks in advance. ...

Python - randomly partition a list into n nearly equal parts

Hi, I have read the answers to the Python: Slicing a list into n nearly-equal-length partitions question. This is the accepted answer: def partition(lst, n): division = len(lst) / float(n) return [ lst[int(round(division * i)): int(round(division * (i + 1)))] for i in xrange(n) ] I am wondering, how does one modify these s...

System-wide seeding of CryptGenRandom

Hi, In the MSDN documentation at http://msdn.microsoft.com/en-us/library/aa379942.aspx the following is written: With Microsoft CSPs, CryptGenRandom uses the same random number generator used by other security components. This allows numerous processes to contribute to a system-wide seed. CryptoAPI stores an intermediate random...

get 5 random favorites from flickr

Hello! I need to retrieve 5 random favorites photos from a flickr profile. I've got perfect Moonpix-Flickr Gem to work with Flickr API. And it works great, by using method .favorites I can get full list of user's favorites photos. It returns as Flickr::PhotoCollection and I don't know how to get 5 random records from it. Thanks in a...

Integration testing with random outcomes

I'd like to write some integration tests for a card game I'm creating. However, it's based on a shuffle. The only solution I can think of to get predictable results to test is stubbing the shuffle, however I'm uncomfortable doing any stubbing in an integration test. Are there any alternative strategies? ...

Quick Sort with random pivot in Java

I've been assigned to implement a quick sort with a random pivot point (because it's supposedly the most efficient/safest way), yet I've been slaving over a bogosort. Can anyone direct me on how to do it? And can someone help me look at my bogosort to see if I can save it anyway? public static void Quick(int[] target, int lo, int hi) ...

Best way to generate a random float in C#

What is the best way to generate a random float in C#? Update: I want random floating point numbers from float.Minvalue to float.Maxvalue. I am using these numbers in unit testing of some mathematical methods. ...

Optimal algorithm for generating a random number R not in a set of numbers N

I am curious to know what the best way to generate a random integer R that is not in a provided set of integers (R∉N). I can think of several ways of doing this but I'm wondering what you all think. ...

How to shuffle the lines in a file without reading the whole file in advance?

What's a good algorithm to shuffle the lines in a file without reading the whole file in advance? I guess it would look something like this: Start reading the file line by line from the beginning, storing the line at each point and decide if you want to print one of the lines stored so far (and then remove from storage) or do nothing an...

Global Variable Not Defined

I'm calling two separate functions to determine what "P01" equals. The first one selects a random number, and discards random numbers already picked. The second one takes the result of the random number and picks a variable to make 'position' equal. I then say that 'P01' equals 'position.' I've made 'position' a global variable, but I k...

Why do digits 1, 2 and 3 appear so frequently using C rand() function?

What I am trying to do is to generate some random numbers (not necessarily single digit) like 29106 7438 5646 4487 9374 28671 92 13941 25226 10076 and then count the number of digits I get: count[0] = 3 Percentage = 6.82 count[1] = 5 Percentage = 11.36 count[2] = 6 Percentage = 13.64 count[3] = 3 Percenta...

Create a random even number between range

OK I need to create an even random number between 54 and 212 inclusive. The only catch is that it has to be done in a single statement. I have a class to generate random number within a range, but like I said, I want to do it in a single statement. I came up with this, but it's not working correctly. Any ideas? int main() { srand( ...

Eliminating Random Duplicates?

I have 3 Subclasses " Staff, Faculty, Student" each class is getting the users first initial lastname from the parent class person, to this id like to add 4 random numbers when the console application is run. The problem I am having is that all of the classes are getting the same 4 digits how can I fix this and yes it has to be done usin...

How to sync up random generation of strings in Python

How could I ensure that a randomizing algorithm would produce the same random number for two different programs. I am trying to make a chat program that utilizes a shared password, or key and then uses that key to generate a random string that is only predictable to both programs. For example Person A: asd4sa5d8s5s5d5sd Person B: asd4s...

How to have unique random number?

This is how i am generating a unique no in between 1 to 6 and getting appropriate images from the drawable folder. Random rand = new Random(); // n = the number of images, that start at idx 1 rndInt = rand.nextInt(6) + 1; String imgName = "card" + rndInt; int id = getResources().getIdentifier(imgName, "drawable", getPackageName()); i...

Select a random row but with odds

I have a dataset of rows each with an 'odds' number between 1 and 100. I am looking to do it in the most efficient way possible. The odds do not necessarily add up to 100. I have had a few ideas. a) select the whole dataset and then add all the odds up and generate a random number between 1 and that number. Then loop through the datase...

Returning random rows from mysql database without using rand()

I would like to be able to pull back 15 or so records from a database. I've seen that using WHERE id = rand() can cause performance issues as my database gets larger. All solutions I've seen are geared towards selecting a single random record. I would like to get multiples. Does anyone know of an efficient way to do this for large datab...