Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is Coldfusion 10 random number generation best practice?

Do you still need to use Randomize if you are using RandRange with an algorithm? For example:

  RandRange(1, 37, "SHA1PRNG")  

Adobe's documentation says:

SHA1PRNG: generates a number using the Sun Java SHA1PRNG algorithm. This algorithm provides greater randomness than the default algorithm.

It would be nice if there was one function which provided the most randomized sequence possible. The example given by Adobe uses both Randomize and RandRange.

Any clarification would be welcome.

Additional info:

In this context I am choosing random characters from a list of about 40 to allocate a password of 7 characters. I'd like to avoid duplicates although there are also separate (though not necessarily unique) usernames. Nothing financial or confidential is at stake - just need to identify users of an educational website.

like image 586
David Eno Avatar asked Jan 22 '14 14:01

David Eno


People also ask

What is the best method to generate true random numbers?

There are two main methods that a computer generates a random number: true random number generators (TRNGs) and pseudo-random number generators (PRNGs). The former uses some phenomenon outside the computer for its number generation, whereas the latter relies on pre-set algorithms to emulate randomness².

What is random number generation used for?

Random number generators have applications in gambling, statistical sampling, computer simulation, cryptography, completely randomized design, and other areas where producing an unpredictable result is desirable.

What are different types of random number generator techniques?

There are generally two kinds of random number generators: non-deterministic random number generators, sometimes called "true random number generators" (TRNG), and deterministic random number generators, also called pseudorandom number generators (PRNG).

How do you generate a random number between 1 and 10 in C?

In this program we call the srand () function with the system clock, to initiate the process of generating random numbers. And the rand () function is called with module 10 operator to generate the random numbers between 1 to 10. srand(time(0)); // Initialize random number generator.


1 Answers

For non-repeating, you gotta reduce the randRange's range and select from a list of unused characters.

Sure, use RandRange with SHA1PRNG and don't worry about it.

You don't really need randomize. It's only used for seeding the random functions when you want predictable random sequence for debugging purposes.

An alternative solution would be shuffling a collection of character using java.util.Collections's shuffle(), then use left() to get the desired length of non-repeating characters. See: http://www.bennadel.com/blog/2284-Using-java-util-Collections-To-Shuffle-A-ColdFusion-Query-Column-Corrupts-Column-Values.htm

like image 199
Henry Avatar answered Oct 20 '22 20:10

Henry