random

Need a repeatable random array shuffle using a key

I am looking to randomly shuffle a list/array using a key. I want to be able to repeat the same random order using the key. So I will randomly generate a numeric key from say 1 to 20 then use that key to try and randomly shuffle the list. I first tried just using the key to keep iterating through my list, decrementing the key until=0,...

jQuery Random Number Not Working

Hey, I am trying to get jQuery to generate a random background on my site body absed off a number. So I'm trying to get it to generate either main1.jpg or main2.jpg and throw it into the body as a background. For some reason it is only generating main2.jpg. Here is my code: $(document).ready(function(){ $("body").css({'background...

100k Rows Returned in a random order, without a SQL time out please

Ok, I've been doing a lot of reading on returning a random row set last year, and the solution we came up with was ORDER BY newid() This is fine for <5k rows. But when we are getting >10-20k rows we are getting SQL time outs, the Execution planned tells me that 76% of my query cost comes from this line. and removing this line increa...

Generate random numbers following a normal distribution in C/C++

Does anyone know how I could easily generate random numbers following a normal distribution in C/C++ ? http://www.mathworks.com/access/helpdesk/help/toolbox/stats/normrnd.html I don't want to use any of Boost. I know that Knuth talk about this at length but I don't have his books at hands right know. Thanks, ...

php get two different random array elements

From an array $my_array = array('a','b','c','d','e'); I want to get two DIFFERENT random elements. With the following code: for ($i=0; $i<2; $i++) { $random = array_rand($my_array); # one random array element number $get_it = $my_array[$random]; # get the letter from the array echo $get_it; } it is possible to g...

How random is Random.Next()?

Hi, I have been doing some testing on the Random class and I have used the following code: while (x++ <= 5000000) { y = rnd.Next(1, 5000000); if (!data.Contains(y)) data.Add(y); else { Console.WriteLine("Cycle {2}: Repetation found for number {0} after {1} ...

arc4random except some numbers

How can you disallow some nubers from being chosen with the arc4random function? Current code: int random = (arc4random() % 92); (numbers from 0 to 92) I want it do disallow the following numbers: 31, 70, 91, 92 Thank you (: ...

Use javascript to randomly append CSS class to one list item

Hey, I don't have any code because I don't know how to do this. I'm looking to use jQuery / javascript to randomly append the CSS class "active" to one list item within a an unordered list id'd as ul#sliding_panels. ...

picking a random line from stdout

I have a command which spouts a number of lines to stdout: $ listall foo bar baz How do I extract a random entry from this, in a one-liner (preferably without awk) so I can just use it in a pipe: $ listall | pickrandom | sed ... | curl ... Thanks! ...

How can I make a Random Word Generator in Visual C#?

All right, so basically all I want is for a bunch of words that I input into a string(would I use one?) and then a random one would be outputted in a TextBox. So, I'd have a list of words (let's say 100 words) and then I'd make it randomly put out 1 of those 100 words in a TextBox. Is this possible? Thanks! ...

How to generate random lines of text of a given length from a dictionary of words (bin-packing problem)?

I need to generate three lines of text (essentially jibberish) that are each 60 characters long, including a hard return at the end of each line. The lines are generated from a dictionary of words of various lengths (typically 1-8 characters). No word may be used more than once, and words must be separated by spaces. I think this is esse...

Random Items in XSLT

I'm customizing a Google Search appliance, which uses XSLT to present results to the user. Our design calls for one of several images to be included randomly on the results page. Is there a way to use randomness in XSLT? (Pseudo-randomness is just fine for this application.) Calling random templates would be fine, as would just being ab...

How is the lagged fibonacci generator random?

I dont get. If it has a fixed length, choosing the lags and the mod over and over again will give the same number, no? ...

Which solution is better for getting random record set from db?

I want to get some random records from db. There is two solution for this : 1- Using TABLESAMPLE for getting data from db directly. 2- Write a method In my application for doing this. In this method we generate multiple random number and get data like this : select * from db where ID = @RandomNumber if this ID does not exist, I pass...

approach using thread programming

This is my scenario. I have a pool of frequencies and my BaseStation needs to select one of them. The critical section for a BaseStation is the phase when it goes into frequency selection. Once it selects frequencies, control returns back to the main BaseStation class and it resumes its request generation. At the same time, i.e. as soon...

Unpredictable Program Behaviour in Java

Hi there, I'm pulling my hair out with this and I thought I'd see if the greater Java experience of others might be able to shed some light on the problem. There is a large amount of program code I have written, which is itself within a larger project so I can't simply post it. However, I will outline the problem... The issue: My code ...

select n random rows via linq2sql

i know of using the ORDER BY NEWID() feature when running a regular sql command. I'm wanting to do the same thing, but via linq2sql. I'd prefer not to select the whole range, add in a random number via rnd.Next(), and then sort by that... ...

Create a random int number that differ from previous run of program.

I use this code to generate a random number. Random R = new Random(0); int Rand = R.Next(7); but i get the same random number in each run of program. ...

How can I randomise <li> elements on page refresh?

Does anyone have any ideas about how I could go about randomising an list each time the page is refreshed? A jQuery solution would be perfect as I'm already using it. Any advice appreciated! ...

Compare 7 words to eachother to see if 5 of them are equal. How?

I have seven words in the array: string[7] = {x,x,x,x,x,x,x}; the x is generated from another array: string[4]={a,b,c,d}; that means each x can be either a or b or c or d. It is randomly generated. this could be an example: string[7]= {a,a,d,a,a,c,a} my question is how can I check if there are five x which has the same value?...