random

Better seeds than time(0)?

I understand that time(0) is commonly using for seeding random number generators and that it only becomes a problem when the program is being run more than once per second. I'm wondering what are some better seeds to consider when generating random numbers. I read about GetTickCount, timeGetTime, and QueryPerformanceCounter on Windows. W...

How to randomly select a string using C#?

When I click a button a string should appear as output ex. good morning or good afternoon. How can I use C# to randomly select the string to display? ...

SQL : select one row randomly, but taking into account a weight

I'm using MySQL. I have a table which looks like that: id: primary key content: varchar weight: int What I want to do is randomly select one row from this table, but taking into account the weight. For example, if I have 3 rows: id, content, weight 1, "some content", 60 2, "other content", 40 3, "something", 100 The first row has 3...

(PostgreSQL) random number range 1 - 10

Hi all, since my approach for a test query which I worked on in this question did not work out I'm trying something else now. Is there a wayto tell pg's random() function to getme only numbers between 1 and 10? thx for your time K ...

How do you seed a PRNG with two seeds?

For a game that I'm making, where solar systems have an x and y coordinates, I'd like to use the coordinates to randomly generate the features for that solar system. The easiest way to do this seems to seed a random number generator with two seeds, the x and y coordinates. Is there anyway to get one reliable seed from the two seeds, or i...

Are there any tools to populate class properties with random data?

What I'd like to do is create a class with some attributes on different properties, pass that class to another that will set the properties with appropriate random data... here in pseudo code: public class Customer { [Attribute("FirstName")] private string CustomerFirstName; public {get;set} //etc [Attribute("LastName")] ...

random and unique subsets generation

Lets say we have numbers from 1 to 25 and we have to choose sets of 15 numbers. The possible sets are, if i'm right 3268760. Of those 3268760 options, you have to generate say 100000 What would be the best way to generate 100000 unique and random of that subsets? Is there a way, an algorithm to do that? If not, what would be the bes...

Non-repeating pseudo random number stream with 'clumping'

I'm looking for a method to generate a pseudorandom stream with a somewhat odd property - I want clumps of nearby numbers. The tricky part is, I can only keep a limited amount of state no matter how large the range is. There are algorithms that give a sequence of results with minimal state (linear congruence?) Clumping means that ...

Is this a good or bad way of generating random numbers for each record?

A colleague of mine discovered a behaviour in SQL Server which I was unaware of. CREATE VIEW dbo.vRandNumber AS SELECT RAND() as RandNumber GO CREATE FUNCTION dbo.RandNumber() RETURNS float AS RETURN (SELECT RandNumber FROM vRandNumber) GO DECLARE @mytable TABLE (id INT) INSERT INTO @mytable SELECT 1 INSERT INTO @mytable SELECT 2 INSE...

generating random values in iPhone

I have used rand(). But it gives a specific value even after I restart application. I have implemented following in my application. - (void)viewDidLoad { [super viewDidLoad]; int x,y; x=random() % 480; y=random() % 300; lblT.center=CGPointMake(x,y); // my label lblT } Try to implement in your application, and launch application. Af...

ASP.NET MVC - How to get random records from model?

Hello there, I don't know if there is an easy way to do it but basically what I would like to do is: var highlights = db.Banners.Where(h => h.Category == "highlight").ToList().GetRange(0,4); I have this model Banners where I have some highlights but I would like to retrieve just 4 random highlights each time in different order. So th...

Random number generation in C#

I have been writing some C# code for a training exercise, in which I had to create an array of random rectangles. Problem being that the rectangle being produced by my GetRandomRectangle function was always the same. I was using System.Random to generate the coordinates for the rectangle. I've realised that it was because the Random ob...

iPhone: random() function gives me the same random number everytime

Hello all, I am using function random()%x for the generation of a random number, but every time I start the application I see that it creates or generates the same number. Like I am placing some images randomly based on that random number and I see all the images are placed at the same place no matter how many times I run the applicat...

How to develop random Analysis Programme?

How to develop random Analysis Programme for selecting students for addmissions in 1st standard among 700 students distributing 24% to general, 11% to SC 5% to St,0.5% to PH? ...

How can I insert random values into a SQL Server table?

I'm trying to randomly insert values from a list of pre-defined values into a table for testing. I tried using the solution found on this StackOverflow question: stackoverflow.com/.../update-sql-table-with-random-value-from-other-table When I I tried this, all of my "random" values that are inserted are exactly the same for all 3000 re...

A Good and SIMPLE Measure of Randomness

What is the best algorithm to take a long sequence of integers (say 100,000 of them) and return a measurement of how random the sequence is? The function should return a single result, say 0 if the sequence is not all all random, up to, say 1 if perfectly random. It can give something in-between if the sequence is somewhat random, e.g. ...

Generate random UTF-8 string in Python

I'd like to test the Unicode handling of my code. Is there anything I can put in random.choice() to select from the entire Unicode range, preferably not an external module? Neither Google nor StackOverflow seems to have an answer. Edit: It looks like this is more complex than expected, so I'll rephrase the question - Is the following co...

In PHP, how do I generate a big pseudo-random number?

I'm looking for a way to generate a big random number with PHP, something like: mt_rand($lower, $upper); The closer I've seen is gmp_random() however it doesn't allow me to specify the lower and upper boundaries only the number of bits per limb (which I've no idea what it is). EDIT: Axsuuls answer seems to be pretty close to what I w...

What's the best practice for getting a random date-time between two date-times?

Hi folks, I'm trying to randomize the value for a simple DateTime datafield. I wish to get a random date/time between two date/times (e.g. min date/time and max date/time). So lets imagine I'm after a random date/time between 1/1/2000 10am and 1/1/2000 5pm. Also, this code will be used in a for loop, with 100 items .. meaning all 10...

difficulty plotting with date column (in R)

I have a random question regarding plotting in R. Here is my code: weather<-read.csv("C:\Users\Tijana\Desktop\CSTAMUWeather08.csv",header=T) weather attach(weather) CST<- as.Date(CST, "%m/%d/%Y") plot(CST,Max TemperatureF,type="l") i am trying to plot a graph that shows temperature for a city, over a year so i have 365 data points for ...