Math.random() versus Random.nextInt(int)
What is the difference between Math.random() * n and Random.nextInt(n) where n is an integer? ...
What is the difference between Math.random() * n and Random.nextInt(n) where n is an integer? ...
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...
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 ...
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? ...
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. ...
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...
Is there a function or will I have to use a third party library? ...
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, ...
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...
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...
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 ...
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...
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 ...
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...
Hi- I need a function that will return a random integer that can be only -1, 0, or 1. Thanks? ...
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...
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...
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...
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...
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). ...