random

How do I create a schedule for n-pastors visiting n-churches?

I want to make a schedule for many pastors. The conditions are: Every month, each pastor must must go to another church, The pastor must not go to same church where he came In 1 year he must go to 12 different churches There is 13 churches and 13 pastors and every church accepts only 1 pastor every month I can't use random(1 to 12) ...

Weighted random selection with and without replacement

Recently I needed to do weighted random selection of elements from a list, both with and without replacement. While there are well known and good algorithms for unweighted selection, and some for weighted selection without replacement (such as modifications of the resevoir algorithm), I couldn't find any good algorithms for weighted sele...

Generating random fixed length permutations of a string

Lets say my alphabet contains X letters and my language supports only Y letter words (Y < X ofcourse). I need to generate all the words possible in random order. E.g. Alphabet=a,b,c,d,e,f,g Y=3 So the words would be: aaa aab aac aba .. bbb ccc .. (the above should be generated in random order) The trivial way to do it would be to gene...

Seeding a random number generator in .Net

I have a PRNG with nice properties which uses 6 UInt32s as state. I need to come up with a reasonable way to seed it. Two obvious possibilities are: 1) generate 6 random numbers using System.Random and use them as seeds; 2) generate 2 Guids with Guid.NewGuid(). Which would be better? I do not need cryptographic security. ...

How can I modify this to get a random record on the many end of a join?

Here is my query: Select Top 10 CS.CaseStudyID, CS.Title, CSI.ImageFileName From CaseStudy CS Left Join CaseStudyImage CSI On CS.CaseStudyID = CSI.CaseStudyID And CSI.CSImageID in( Select Min(CSImageID) -- >not really satisfactory From CaseStudyImage Group By CaseStudyID ) Order By CS.CaseStudyID ASC Instea...

Most efficient way to randomly "sort" (Shuffle) a list of integers in C#

I need to randomly 'sort' a list of integers (0-1999) in the most efficient way possible. Any ideas? Currently, I am doing something like this: bool[] bIndexSet = new bool[iItemCount]; for (int iCurIndex = 0; iCurIndex < iItemCount; iCurIndex++) { int iSwapIndex = random.Next(iItemCount); if (!bIndexSet[iSwapIndex] && iSwapIn...

What's the efficiency and quality of this shuffling algorithm?

This recent question about sorting randomly using C# got me thinking about the way I've sometimes shuffled my arrays in Perl. @shuffled = sort { rand() <=> rand() } @array; The proposed solution in the mentioned question is Fisher-Yates shuffle, which works in a linear time. The question is: how efficient is my snippet and is such sh...

random string generation - two generated one after another give same results

i've god a simple piece of code: public string GenerateRandomString() { string randomString = string.Empty; Random r = new Random(); for (int i = 0; i < length; i++) randomString += chars[r.Next(chars.Length)]; return randomString; } If i call this functi...

How to select N random rows using pure SQL?

How do we combine http://stackoverflow.com/questions/19412/how-to-request-a-random-row-in-sql and http://stackoverflow.com/questions/183124/multiple-random-values-in-sql-server-2005 to select N random rows using a single pure-SQL query? Ideally, I'd like to avoid the use of stored procedures if possible. Is this even possible? CLARIFICA...

How to return random items RESTfully?

My design exposes two kinds of resources: Images Tags I would like clients to be able to request random images by their tag(s). For example: Give me random images that are tagged with "New York" and "Winter". What would a RESTful design look like in this case? ...

Randomize a string in C

I'm trying to generate random permutations of an 80-character fixed string in C. Much to my dismay, the system I'm working on lacks strfry(). What's the best way for me to generate a random permutation of this string? Since this will be looped over approx. 100,000 times, performance is an issue. ...

Pin Generation

Hi, I am looking to develop a system in which i need to assign every user a unique pin code for security. The user will only enter this pin code as a means of identifying himself. Thus i dont want the user to be able to guess another users pincode. Assuming the max users i will have is 100000, how long should this pin code be? e.g. 123...

Programmatically choose high-contrast colors

This should be a simple question, but I haven't been able to find a way to make it work. Essentially, I have a silly localhost page that I use in my webdevelopment. When I am surfing between our development server and my local version of the C# code (redirected from the dev url via host file) I have been known to sometimes forget what ...

How random is System.Random in .net 3 ?

I am currently writing a simple password generator (C#). For that I need some random Numbers. Is it OK to simply use the Random Class that ships with .NET or are there any known problems with that? ...

How can I select random files from a directory in bash?

I have a directory with 2000 files or so. I want a script or a list of piped commands that will allow me to select a random sample of N files. ...

What is the best way of randomly re-arranging a list of items in c# ?

I have a list of objects and I want to reorder them randomly on each request. What is the best way of doing this? ...

Pros and cons of RNGCryptoServiceProvider

What are the pros and cons of using System.Security.Cryptography.RNGCryptoServiceProvider vs System.Random are. I know that RNGCryptoServiceProvider is 'more random', i.e. less predictable for hackers. Any other pros or cons? UPDATE: According to the responses, here are the pros and cons of using RNGCryptoServiceProvider so far: Pro...

random Decimal in python

How can I get a random decimal.Decimal? it appears that the random module only returns floats which are a pita to convert to Decimals. ...

How do I create a random alpha-numeric string in C++?

I'd like to create a random string, consisting of alpha-numeric characters. I want to be able to be specify the length of the string. How do I do this in C++? ...

Generating random results by weight in PHP?

I know how to generate a random number in PHP but lets say I want a random number between 1-10 but I want more 3,4,5's then 8,9,10's. How is this possible? I would post what I have tried but honestly, I don't even know where to start. ...