Can XorShift return zero?

I've been reading about the XorShift PRNG especially the paper here A guy here states that The number lies in the range [1, 2**64). Note that it will NEVER be 0. Looking at the code that makes sense: uint64_t x; uint64_t next(void) { x ^= x >> 12; /

Randomization R command

I'm afraid I can't find an answer to my problem. I am looking to create 1) They are 4 sets of cards A, B, C, D and 16 cards. 2) Each card is numbered within a set (A from 1 to 4, B from 5 to 8, and so on). 3) We want to randomize the assignment such

How can I choose a random value between 0 and a bigint?

I have a combinatorics problem for which I want to be able to pick an integer at random between 0 and a big integer. Inadequacies of my current approach Now for regular integers I would usually write something like int rand 500; and be done with it.

How to stop uniqid () from regenerating in PHP form

I want to generate a random key for the user to use during registration. The code compares the generated key with the user input but the key gets regenerated when the user submits the form, so they are never the same. I tried to protect the generator

Store random integers in a table

package selectionsortintro; public class SelectionSortIntro { public static void main(String[] args) { int nums[] = { 22, 30, 15, 1, 7, 87, 65, 24, 22, 0 }; // print out unsorted list for (int count = 0; count < nums.length; count++) { System.out.pri

How can I do a random event in Java?

So I'm making a game, and I want the user to be able to fight crimes. Only I don't want them to be able to fight crimes again for a period of time, a 10 second delay max. I know that I could use Math.Random() somehow, but I'm having trouble figuring

Random on ThreadLocalRandom

Instances of java.util.Random are threadsafe. However, the concurrent use of the same java.util.Random instance across threads may encounter contention and consequent poor performance. Consider instead using ThreadLocalRandom in multithreaded designs

Dynamic generation of a 2D array with different column lengths

For testing purposes I currently ran into a situation, where I had to randomly create a two dimensional array with columns of potentially different lengths for each row. For example consider this illustration: 0.0 0.1 length = 2 1.0 1.1 1.2 length =

Two random tables

I want to fill 2 arrays with random numbers, i have to use srand(time(NULL)), but when i do the arrays have the same numbers.I created the second array through a function so the time will be different but again the arrays have the same numbers. #incl

random boost in 2 dimensions

I am trying to use a boost random generator to make random points uniformly distributed over a plane surface. I have the following link for doing it in a single dimension: Boost random number generator Here they use boost::uniform_int<> to generate

Random number generator to cover all the numbers in the set

I am writing an Android app and I want to generate random numbers. But, Java's RandomGenerator gives me only pseudo random numbers. The numbers repeat and not all the numbers are covered. I want something that will give me non-repeating numbers and w

Generate a random value 1 / x

In java when i want to generate a gaussien value, i use directly Random r = new Random(); r.nextGaussian(); but now i want to generate a value with 1/x probability instead Gauss ! in my solution, i must create a randomly values but these values begin

Procedural generation of the world

I am generating my world (random, infinite and 2d) in sections that are x by y, when I reach the end of x a new section is formed. If in section one I have hills, how can I make it so that in section two those hills will continue? Is there some kind

Is there a way to generate a seed on a sequence of numbers?

For example if java produces the pseudorandom sequence: 9 3 2 5 6 by using 23 as a seed, how can I do the inverse? i.e. getting 23 out of the sequence 9 3 2 5 6. Or how do I assign a seed for a certain sequence? It is easy to do if there is a databas

PHP generates a single string

I have an ID column in a table which stores the row ID number (auto increment), For example 1, 2, 3. I want to generated a random and unique string which could contain only numbers, alphabets and dash (-) and underscore (_). The length of string shou

Best way to randomize (Ruby / Rails 3)

This question already has an answer here: Rails select random record 7 answers I'm currently using: @users = User.order("RANDOM()").limit(6) to generate a list of 6 random users - however, this method takes a 1200ms toll on page load times. Is t

The best way for Unique Random String for MySQL long table

I know how to create random chars both at PHP and MySQL but the question is that I have to create a 4 char random string for a table of 10 thousand or so rows. What way is the best to make sure it will remain unique? I can use a longer string if I ne

Make a string with a string and an integer in Python

I get this error when trying to take an integer and prepend "b" to it, converting it into a string: File "program.py", line 19, in getname name = "b" + num TypeError: Can't convert 'int' object to str implicitly That's relate

Random image display

I have a list of images that need to be displayed. However theres only space for 5. I need to display 5 of these at a time randomly. Whats the best way to do this?If you have the list of images in an array, you could use shuffle().

problem with Random.nextGaussian ()

Random.nextGaussian() is supposed to give random no.s with mean 0 and std deviation 1. Many no.s it generated are outside range of [-1,+1]. how can i set so that it gives normally distributed random no.s only in the range -1 to 1.A Gaussian distribut

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