random

How do I update a fields in table with strings randomly selected from a known list?

I have a table named "buildings" that contains a varchar(50) field named "use". The table already has several thousand records, however the "use" values are all null. I would like to update these this table with randomly chosen values from a list of strings (e.g., warehouse, office, market, retail, workshop). I would also like to leave...

How to select a set number of random records where one column is unique?

I've been struggling with this one SQL query requirement today that I was wondering if someone could help me with. I have a table of sports questions. One of the columns is the team related to the question. My requirement is to return a set number of random questions where the teams are unique. So lets say we have the following table a...

Pseudo Random Sort in MS SQL (not NEWID() and not RAND())

I would like to randomly sort a result in a repeatable fashion for purposes such as paging. For this NEWID() is too random in that the same results cannot be re-obtained. Order by Rand(seed) would be ideal as with the same seed the same random collection would result. Unfortunately, the Rand() state resets with every row… does anyone ...

Why is the first random number always the same on some platforms in lua ?

Consider the following lua code snippet : local time = os.time() for _= 1, 10 do time = time + 1 print('Seeding with ' .. time) math.randomseed(time) for i = 1, 5 do print('\t' .. math.random(100)) end end On a Linux machine, the result is, as expected, random numbers. But it seems that at least on Mac OS X, t...

Generating shuffled range using a PRNG rather than shuffling

Is there any known algorithm that can generate a shuffled range [0..n) in linear time and constant space (when output produced iteratively), given an arbitrary seed value? Assume n may be large, e.g. in the many millions, so a requirement to potentially produce every possible permutation is not required, not least because it's infeasibl...

C++. Is it possible that a RNG gives different random variable in two different machines using the same seed?

Hi everybody, I have this long and complex source code that uses a RNG with a fix seed. This code is a simulator and the parameters of this simulator are the random values given by this RNG. When I execute the code in the same machine, no matter how many attempts I do the output is the same. But when I execute this code on two differe...

How Random is System.Guid.NewGuid()?

I know this may sounds like a pointless question, but hear me out... I basically want to know if I can trust the GUID to generate a value which will be unique 100% of the time and impossible to predict. I'm basically rolling my on login system for a website and want to know if the GUID is secure enough for session cookies. Any backgro...

Creating a unique alphanumeric 10-character string

I'm looking to create a simple short-lived reservation system, and I'd like to generate confirmation numbers that are unique random-looking alphanumeric short-ish, at least much shorter than 32 character-long strings returned by sha1 I'm only looking to have ~500 reservations, so I don't imagine high likelyhood of collissions. One i...

Is a subset of a random sequence also random?

Given: a sequence of random numbers X clients select Y numbers from the sequence, forming their own sub-sequences the rules governing the selection process is not known Is there a mathematical property that guarantees that each client will end up with a random sequence of numbers? That is, is a subset of a random sequence also guaran...

Generate a series of random numbers that add up to N in c#

How do I generate 30 random numbers between 1-9, that all add up to 200 (or some arbitrary N), in C#? I'm trying to generate a string of digits that can add together to be N. ...

How do I simulate flip of biased coin in python?

In unbiased coin flip H or T occurs 50% of times. But I want to simulate coin which gives H with probability 'p' and T with probability '(1-p)'. something like this: def flip(p): '''this function return H with probability p''' # do something return result >> [flip(0.8) for i in xrange(10)] [H,H,T,H,H,H,T,H,H,H] ...

How do you generate a random number in Assembly language using the FASM compiler?

Hey guys, I'm really new to assembly and I'm trying to create a simple program. For this I need to generate a random number. Anybody know how I can do this with the FASM compiler? Thanks, Sam ...

How to test for sometimes fails?

I'm trying to write a unit test for a module that will give me a random list of numbers given certain criteria. The particular test I'm writing is a reshuffle of the original sequence. I'm testing that The sequences are the same length The sequences have the same values The sequences are not in the same order The problem with this i...

Going to a Random page PHP

I have a link that goes to http://example.com/random.php, code for random.php below. <?php srand ((double) microtime( )*1000000); $random_number = rand(1,100); header( "Location: http://example.com/test?page=$random_number" ) ; ?> Basically what I want it to do is link to a random page. It works initially, but after the first click i...

How can I create a random simulation?

I've been playing this flash game and after I'd gotten over the initial ('lol, fire') reaction I started to wonder how I could replicate this contact-mutate behaviour in programming. I guess it's a little like the honeypot xkcd. I was thinking of starting with a scenario where particles deflect off each other and the containing walls. T...

Random name generator strategy - help me improve it

I have a small project I am doing in Python using web.py. It's a name generator, using 4 "parts" of a name (firstname, middlename, anothername, surname). Each part of the name is a collection of entites in a MySQL databse (name_part (id, part, type_id), and name_part_type (id, description)). Basic stuff, I guess. My generator picks a ra...

Generate sequence of integers in random order without constructing the whole list upfront

How can I generate the list of integers from 1 to N but in a random order, without ever constructing the whole list in memory? (To be clear: Each number in the generated list must only appear once, so it must be the equivalent to creating the whole list in memory first, then shuffling.) This has been determined to be a duplicate of thi...

Pseudorandom directory tree generation?

I'm trying to write a program which will pseudorandomly autogenerate (based on a seed value so I can re-run the same test more than once) a growing directory structure consisting of files. (this is to stress test a source control database installation) I was wondering if any of you were aware of something similar to the quasirandom "spa...

Javascript Random Seeds

Is it possible to seed the random number generator (Math.rand) in Javascript ? ...

Sequentially firing multiple random timeouts in JavaScript

Hello All, I know at first glance (due to the title) this looks like one of the "Did you try searching Google before posting?" questions, but I can't seem to find an answer for the specific issue I'm experiencing. Sorry if I'm a noob.... still learning :) I need to simulate a pause in javascript, but the setTimeout(function_call, tim...