random-number-generator

Math.random() versus Random.nextInt(int)

What is the difference between Math.random() * n and Random.nextInt(n) where n is an integer? ...

Please help me get my random number generating working in Java

I am trying to make a Java implementation of the Park-Miller-Carta PRNG random number generator (maybe faster?) Below is the implementation of the Random function in ActionScript 3 from here. return (_currentSeed = (_currentSeed * 16807) % 2147483647) / 0x7FFFFFFF + 0.0000000002...

C++ Random Seed, Global Objects, and SDL_Threads

In my program, I have an object the global cpp file, that takes an integer as an argument. //In global header extern Object example; //In global cpp file Object example( (rand() % 6) ); I want a random number to be generated to the object's argument, but the seed does not reach the global variable, as the seed created in another cpp ...

Random number generation on Spartan-3E

I need to generate pseudo-random numbers for my genetic algorithm on a Spartan-3E FPGA and i want to implement it in verilog: could you give me any pointers on this? ...

Random numbers from physical sources on the Internet

What are the addresses of some websites that offers random numbers from physical sources? I'm looking both for free services and services that cost money. ...

Random strings in Python 2.6 (Is this OK?)

I've been trying to find a more pythonic way of generating random string in python that can scale as well. Typically, I see something similar to ''.join(random.choice(string.letters) for i in xrange(len)) It sucks if you want to generate long string. I've been thinking about random.getrandombits for a while, and figuring out how to c...

How to generate a random number in C?

Is there a function or will I have to use a third party library? ...

Is there an Equivalent of .Net framework's Random.Next(Int32, Int32) in the Java API ?

I am working on porting an existing VB.Net application to Java, and could not find an equivalent to Random.Next(Int32, Int32). I could find only "java.util.Random.next(int val)" in the Java API. Is there an Equivalent of .Net framework's Random.Next(Int32, Int32) in the Java API? Thanks, ...

Database-Generated Human-Friendly Codes

I'd like to create some human-friendly codes to identify my objects. I'm thinking about using the following rules: 6-digit random number the first character is not zero each code has an edit distance value of 2 or greater* from every other such code maybe a checksum too I'd like my MS SQL database to enforce that the codes I use are...

C++ adding a carriage return at beggining of string when reading file

I have two questions: 1) Why is my code adding a carriage return at the beggining of the selected_line string? 2) Do you think the algorithm I'm using to return a random line from the file is good enough and won't cause any problems? A sample file is: line number one # line number two My code: int main() { srand(time(0)); i...

Select n random rows from SQL Server table

I've got a SQL Server table with about 50,000 rows in it. I want to select about 5,000 of those rows at random. I've thought of a complicated way, creating a temp table with a "random number" column, copying my table into that, looping through the temp table and updating each row with RAND(), and then selecting from that table where the ...

quickest way to generate random bits

What would be the fastest way to generate a large number of (pseudo-)random bits. Each bit must be independent and be zero or one with equal probability. I could obviously do some variation on randbit=rand()%2; but I feel like there should be a faster way, generating several random bits from each call to the random number generato...

Efficient algorithm to randomly select items with frequency

Given an array of n word-frequency pairs: [ (w0, f0), (w1, f1), ..., (wn-1, fn-1) ] where wi is a word, fi is an integer frequencey, and the sum of the frequencies fi = m, I want to use a pseudo-random number generator (pRNG) to select p words wj0, wj1, ..., wjp-1 such that the probability of selecting any word is proportional to its ...

Generating random number in a given range in Fortran 77

I am a beginner trying to do some engineering experiments using fortran 77. I am using Force 2.0 compiler and editor. I have the following queries: How can I generate a random number between a specified range, e.g. if I need to generate a single random number between 3.0 and 10.0, how can I do that? How can I use the data from a text f...

Java Generate Random number {-1,0,1}

Hi- I need a function that will return a random integer that can be only -1, 0, or 1. Thanks? ...

How to generate "random" but also "unique" numbers ?

How are random numbers generated.? How do languages such as java etc generate random numbers, especially how it is done for GUIDs.? i found that algorithms like Pseudorandomnumber generator uses initial values. But i need to create a random number program, in which a number once occurred should never repeats even if the system is resta...

Need for predictable random generator

I'm a web-game developer and I got a problem with random numbers. Let's say that a player has 20% chance to get a critical hit with his sword. That means, 1 out of 5 hits should be critical. The problem is I got very bad real life results -- sometimes players get 3 crits in 5 hits, sometimes none in 15 hits. Battles are rather short (3-1...

c++ not randomizing

i'm not sure why i cant get diff values for my variables here, help! int main() { srand(time(NULL)); srand48(time(NULL)); Packet* firstPacket = new Packet(); firstPacket->packetSize = randSize(); firstPacket->dest = randDest(); firstPacket->arrivalTime = myExp(lamb); Host[firstPacket->dest].Frame.push_back(f...

Random number generator that produces a power-law distribution?

I'm writing some tests for a C++ command line Linux app. I'd like to generate a bunch of integers with a power-law/long-tail distribution. Meaning, I get a some numbers very frequently but most of them relatively infrequently. Ideally there would just be some magic equations I could use with rand() or one of the stdlib random functi...

Consistent pseudo-random numbers across platforms

Hello, I am looking for a way to generate pseudo random number sequences that will yield identical sequence results for a given seed across any platform. I am assuming that rand()/srand() is not going to be consistent (I could easily be wrong about this assumption). ...