Just need a fast way to generate pseudo-random numbers between -1 and 1 on the GPU.
I've been looking at the xorshift random number generators, but I can't figure out how to constrain them between two numbers.
Related
We want to generate a uniform random number from the interval [0, 1].
Let's first generate k random booleans (for example by rand()<0.5) and decide according to these on what subinterval [m*2^{-k}, (m+1)*2^{-k}] the number will fall. Then we use one rand() to get the final output as m*2^{-k} + rand()*2^{-k}.
Let's assume we have arbitrary precision.
Will a random number generated this way be 'more random' than the usual rand()?
PS. I guess the subinterval picking amounts to just choosing the binary representation of the output 0. b_1 b_2 b_3... one digit b_i at a time and the final step is adding the representation of rand() to the end of the output.
It depends on the definition of "more random". If you use more random generators, it means more random state, and it means that cycle length will be greater. But cycle length is just one property of random generators. Cycle length of 2^64 usually OK for almost any purpose (the only exception I know is that if you need a lot of different, long sequences, like for some kind of simulation).
However, if you combine two bad random generators, they don't necessarily become better, you have to analyze it. But there are generators, which do work this way. For example, KISS is an example for this: it combines 3, not-too-good generators, and the result is a good generator.
For card shuffling, you'll need a cryptographic RNG. Even a very good, but not cryptographic RNG is inadequate for this purpose. For example, Mersenne Twister, which is a good RNG, is not suitable for secure card shuffling! It is because observing output numbers, it is possible to figure out its internal state, so shuffle result can be predicted.
This can help, but only if you use a different pseudorandom generator for the first and last bits. (It doesn't have to be a different pseudorandom algorithm, just a different seed.)
If you use the same generator, then you will still only be able to construct 2^n different shuffles, where n is the number of bits in the random generator's state.
If you have two generators, each with n bits of state, then you can produce up to a total of 2^(2n) different shuffles.
Tinkering with a random number generator, as you are doing by using only one bit of random space and then calling iteratively, usually weakens its random properties. All RNGs fail some statistical tests for randomness, but you are more likely to get find that a noticeable cycle crops up if you start making many calls and combining them.
I am confused about the concept of uniform distribution and random number. Does random number follow uniform distribution or does random number not follow any distribution?
Traditionally, random is just that, random. There is nothing that guarantees that after 100 random numbers, at least one of them is non-zero. You'd probably think something is broken, and while you'd probably be right, it is just as possible as any other combination of numbers in the same given range.
Uniform distribution will ensure that statistically speaking, your values will be spread out across a given range. In that case if you got 100 random uniformly distributed numbers and they were all zero, something is definitely broken.
Any number generator guaranteeing a uniform distribution is not random. That said, the more numbers you generate, the more likely it is to resemble a uniform distribution.
I want to use rejection sampling to generate random numbers from a given distribution. I want to be quite general so that I don't want to relay on things like Box-Muller transformation which can generate only normal distributed random numbers. I am using linear congruential generator to generate a random sequence between 0 and 1 with uniform distribution. To use rejection sampling, I need to generate two sequences of random numbers so that I would be able to generate uniform points inside a 2d region. This can be done using two random sequences (one for x coordinate and other for y coordinate). I searched on Internet but nowhere I saw how to make sure that these two sequences are really uncorrelated. Is there any way to choose seeds for these such that these sequences are uncorrelated? If I randomly give seeds then the final distribution of these numbers is not quite like what I am looking for.
Thank you
I'm trying to generate some 8-bit random numbers with C++ and don't want to use divisions (like rand()%8 or any scale methods).
One algorithm I found online is Park-Miller-Carta Pseudo-Random Number Generator
It is a 32-bit random number generator with no divisions. With these random numbers, I'm trying to extract the lower or higher 8 bits of them so that I can get some random bytes, but this does not seem to work because these bits are not so random.
Are there any tricks to fix this or are there any other algorithms that can do the trick?
How about XORing four bytes of 32bit random integer?
So I get that all the built in function only return pseudo random numbers as they use the clock speed or some other hardware to get the number.
So here my idea, if I take two pseudo random numbers and bitwise them together would the result still be pseudo random or would it be closer to truly random.
I figured that if I fiddled about with the number a bit it would be less replicable, or am I getting this wrong.
On a side note why is pseudo random a problem?
It will not be more random, but there is a big risk that the number will be less random (less uniformly ditributed). What bitwise operator were you thinking about?
Lets assume 4-bit random numbers 0101, 1000. When OR:ed together you would get 1101. With OR there would be a clear bias towards 1111, with AND towards 0000. (75 % of getting a 1 or 0 respectively in each position)
I don't think XOR and XNOR would be biased. But also you wouldn't get any more randomness out of it (see Pavium's answer).
Algorithms executed by computers are deterministic.
You can only generate truly random numbers if there's a non-deterministic input.
Pseudo-random numbers follow a repeating sequence. Maybe a long sequence but the repetition makes them predictable and therefore not truly random.
You can't generate truly random numbers from two pseudo-random numbers.
EDITED: to put the sentences in a more logical order.