>Take a look at this site:

http://www.lavarnd.org/

The LavaCan is Interesting. However, I recall seeing tiny devices which plug into the RS232 port and cost around $20 from RS Components.

Printable View

- 05-31-2004Davros
>Take a look at this site:

http://www.lavarnd.org/

The LavaCan is Interesting. However, I recall seeing tiny devices which plug into the RS232 port and cost around $20 from RS Components. - 06-02-2004pianorainQuote:

Originally Posted by**Thantos**

- 06-02-2004JasonD
The book's contents may be truly random numbers, like those obtained by throwing dice, rather than pseudo random numbers generated by a computer. Basically, one set can be reproduced exactly, the other can not. I would assume a book would use a set that can not. I think that they would still be classified as random numbers, as you can start anywhere in the book, and as long as you don't already have the list memorized, you cannot determine which number will appear next - just like the die.

And even if we live in a deterministic universe, it would be very difficult to set up the environment - the entire universe - exactly as before to achieve the same results. In fact, we would not even realize that we were repeating the experiment as we would all have the same thoughts and memories as the first time. - 06-02-2004anonytmouse
If you need a 'better' random number on windows check out CryptGenRandom().

Quote:

*CryptGenRandom documentation*

The data produced by this function is*cryptographically random*. It is far more random than the data generated by the typical random number generator such as the one shipped with your C compiler.

This function is often used to generate random initialization vectors and salt values.

Software random number generators work in fundamentally the same way. They start with a random number, known as the seed, and then use an algorithm to generate a pseudo-random sequence of bits based on it. The most difficult part of this process is to get a seed that is truly random. This is usually based on user input latency, or the jitter from one or more hardware components.

With Microsoft CSPs, CryptGenRandom uses the same random number generator used by other security components. This allows numerous processes to contribute to a system-wide seed. CryptoAPI stores an intermediate random seed with every user. To form the seed for the random number generator, a calling application supplies bits it might have—for instance, mouse or keyboard timing input—that are then added to both the stored seed and various system data and user data such as the process ID and thread ID, the system clock, the system time, the system counter, memory status, free disk clusters, the hashed user environment block. This result is SHA-1 hashed, and the output is used to seed an RC4 stream, which is then used as the random stream and used to update the stored seed. If an application has access to a good random source, it can fill the pbBuffer buffer with some random data before calling CryptGenRandom. The CSP then uses this data to further randomize its internal seed. It is acceptable to omit the step of initializing the pbBuffer buffer before calling CryptGenRandom.

- 06-14-2004weirdbeardmtMore randomness
Hi, sorry if I'm asking a dumb question (having looked through the FAQ/boards etc), but here goes:

I need to generate a list of numbers from 1 (to a set number, for e.g. 25) in a random order. However, I can't have the same number twice, but I need the list ordering to be random.

ANy thoughts? - 06-14-2004Thantos
Have an array that will store the numbers, a variable that will tell you how many items are in the array, and a temporary variable that will hold the result of each random call.

Process would be:

1) call the random generator and put value into the temporary variable

2) Search the array (using the above mentioned variable to make sure you only look at values you've put in already).

3) If you didn't find a match, add in the temp and increase the size counter. Repeat until filled - 06-14-2004PreludeQuote:

Originally Posted by**Thantos**

Code:`#include <algorithm>`

#include <cstdlib>

#include <iostream>

using namespace std;

double random();

int

main()

{

int *vals;

int n;

cout<<"Upper limit: ";

if (!(cin>> n)) {

cerr<<"Input error"<<endl;

exit(EXIT_FAILURE);

}

// Make and fill array

vals = new int[n];

for (int i = 0; i < n; i++) {

vals[i] = i + 1;

}

// Random permutation

for (int i = 0; i < n - 1; i++) {

int x = static_cast<int>(random() * (n - i));

swap(vals[i], vals[i + x]);

}

// Prove that it works and clean up

for (int i = 0; i < n; i++) {

cout<< vals[i] <<endl;

}

delete [] vals;

}

double

random()

{

return static_cast<double>(std::rand()) / RAND_MAX;

}

- 06-14-2004Thantos
But what if you only wanted 20 numbers with a max value of 10000?

And I wasn't going for efficiently but ease of use and understanding for the questioner :) - 06-14-2004Prelude
>But what if you only wanted 20 numbers with a max value of 10000?

Then I would use a more suitable data structure than a simple array. ;) But that wasn't the question. The question was a list of numbers from 1 to N in random order.

Quote:

I need to generate a list of numbers from 1 (to a set number, for e.g. 25) in a random order.

I know, but I can't resist giving you a hard time every now and then. It keeps you on your toes. ;) - 06-14-2004laserlightQuote:

I'm not sure why Preludes indicates that rand()/RAND_MAX is less likely to give a string of equal values on repeated values than rand()/modulus

Quote:

Using the low order bits of a random number may not result in a good distribution. I've seen long strings of repeating numbers when using modulus with rand.

Her argument is that dividing by RAND_MAX conserves this distribution, while the modulo method often does not. - 06-14-2004JasonDQuote:

Originally Posted by**weirdbeardmt**

1. create the list storing 1..25, in order, in the indices 0..24

2. loop through the indicies, i = 0..24, pick a random index, j = 0..24, and swap the two.

This way, you swap a random index with each position, assuring that each index is swapped out at least once. - 06-14-2004laserlight
hmm... I did not see before posting that this thread was already several pages in length.

Anyway...

Quote:

Any deterministic random number generator is predictable, i.e. rand().

Quote:

There are devices which you can plug into your computer in order to generate non-deterministic random numbers.

For a pseudo-random number generator, I tend to use the Mersenne Twister, with a particular C++ implementation by Rick Wagner. - 06-14-2004Sang-drax
The problem with rand()%n using only the lower order bits is only a problem when n is a power of two.

Thus, the problem with rand()%n is not that much of a problem.

If you write rand()%3, the higher-order bits should also be taken into consideration.

Am I not correct, Prelude?

Quote:

There are devices which you can plug into your computer in order to generate non-deterministic random numbers.

http://www.strandmark.com/otp.shtml - 06-14-2004laserlightQuote:

The problem with rand()%n using only the lower order bits is only a problem when n is a power of two.

Thus, the problem with rand()%n is not that much of a problem.

If you write rand()%3, the higher-order bits should also be taken into consideration.