random

MYSQL insert random from list.

I would like to add a random value to a table. While I know how to add random integers within a range, I am currently stumped on how to add a randomly selected item from a list. Let's say I have a MYSQL table for IM accounts. I would like to fill it with random data. INSERT INTO `im` (`im`, `service`) SELECT LOWER(`last`), RANDOM-SELEC...

How to generate normally distributed random from an integer range?

Given the start and the end of an integer range, how do I calculate a normally distributed random integer between this range? I realize that the normal distribution goes into -+ infinity. I guess the tails can be cutoff, so when a random gets computed outside the range, recompute. This elevates the probability of integers in the range, ...

How can I generate pseudo-random "readable" strings in Java?

Generating a truly random string of a given length is a fairly straightforward (and already-well-covered) task. However; I'd like to generate a "pseudo" random string with the additional constraint that it be relatively easily readable (to a native-English reader.) I think another way to say this is to say that the generated string sho...

replace rand() with openssl_random_pseudo_bytes()

I need a replacement for PHP's rand() function that uses a cryptographically strong random number generator. The openssl_random_pseudo_bytes() function gets you access to the strong random number generator, but it outputs its data as a byte string. Instead, I need an integer between 0 and X. I imagine the key is to get the output of o...

sql server 2005 query - random child rows of UNIQUE random parent rows

I got a parent table 'ProductCategory' and a child table 'Product'. I have this query that returns 3 random products: SELECT TOP (3) ProductId FROM Product ORDER BY NEWID(); I want to enhance that query to achieve that all the products are from different product categories. So the query to get unique categories would be: SELE...

(PHP) randomly insert a 10 word sentence into a large text document

I have large text files 140k or larger full of paragraphs of text and need to insert a sentence in to this file at random intervals only if the file contains more then 200 words. The sentence I need to insert randomly throughout the larger document is 10 words long. I have full control over the server running my LAMP site so I can use...

Generating random strings with T-SQL

If you wanted to generate a pseudorandom alphanumeric string using T-SQL, how would you do it? How would you exclude characters like dollar signs, dashes, and slashes from it? ...

How do you generate a random double uniformly distributed between 0 and 1 from C++?

How do you generate a random double uniformly distributed between 0 and 1 from C++? Of course I can think of some answers, but I'd like to know what the standard practice is, to have: Good standards compliance Good randomness Good speed (speed is more important than randomness for my application). Thanks a lot! PS: In case that ma...

Randomize Time Portion of Date Field

What is the best way to randomize the time part for a DATE column, using Oracle 10g? For example, the date portion for the data was set as follows: UPDATE table_name SET column_ts = SYSDATE - 120 + MOD(ROWNUM, 35) I would like the time portion to have a different value for each row. ...

Find out what a random number generator was seeded with in C++

I've got an unmanaged c++ console application in which I'm using srand() and rand(). I don't need this to solve a particular problem, but was curious: is the original seed passed to srand() stored somewhere in memory that I can query? Is there any way to figure out what the seed was? ...

how does random() actually work?

Every language has a random() function or something similar to generate a pseudo-random number. I am wondering what happens underneath to generate these numbers? I am not programming anything that makes this knowledge necessary, just trying to satisfy my own curiosity. Thanks. ...

Objective C - Random results is either 1 or -1

I am trying randomly generate a positive or negative number and rather then worry about the bigger range I am hoping to randomly generate either 1 or -1 to just multiply by my other random number. I know this can be done with a longer rule of generating 0 or 1 and then checking return and using that to either multiply by 1 or -1. Hop...

Is it possible to have randomness in server-side includes?

I want to introduce some random* behavior into an otherwise static html file. I want to experiment with two different advertising schemes, and I want to have the page erved randomly with either one or the other. It seems like overkill to use a scripting language to generate the whole thing, so I thought SSI would be ideal. I want to d...

Generate random numbers distributed by Zipf

The Zipf probability distribution is often used to model file size distribution or item access distributions on items in P2P systems. e.g. "Web Caching and Zip like Distribution Evidence and Implications", but neither Boost or the GSL (Gnu Scientific Library) provide an implementation to generate random numbers using this distribution. I...

Testing for a new random value that doesn't exist in a set

During testing, I'm stuck with testing a piece of code that receives a list of numbers and that's supposed to return a new random key that doesn't exist in the list. The valid range is any number between 1 and 1,000,000 - which makes it too hard to brute-force in tests. What's the best approach for testing this? I've considered testing...

Ruby - Executing tests in a random order with rake

How can I have the tests for my Rails app to be executed in a random order? Is there a simple solution using rake? ...

Generating Random Numbers in Objective C for iPhone SDK

I was using the arc4random() function in order to generate a random group and sequence of numbers, but I was told that this was overkill and that I should use the random() function instead. However, the random() function gives me the same group and sequence of numbers every time. I call srand(time(0)) once when my app first starts in or...

Using Randomize() before Rnd() in vb.net

I have previously been told that I should always use Randomize() before I use Rnd() in a vb.net application, yet it always seems to work fine without it. What does adding Randomize() do for me in this case? It doesnt appear to affect my application in the least. Thanks for the help! ...

Randomly choose a node in XSLT

Hi all I have a question about some sort af random function in XSLT. I have an XML-file that very simplified look similar to this: <node id="1198"> <node id="1201"> <data alias="name">Flemming</data> <data alias="picture">1200</data> </node> <node id="1207"> <data alias="name">John</data> <data alias="picture">12...

Biased random number sources

I'm not sure what the appropriate terminology is, but in trying to run simulations, I always find it tricky to create good fake data. I don't have an particular application for this, but let's say I want to play around with some silly stock market predicting algorithm - if I were to just use a standard random number generator to get my ...