Randomization Question - Get a Clear & Informative Response

  • Thread starter hoangr
  • Start date
In summary, a random function depends on the randomizer which produces a sequence of numbers that look random. It is important to initialize the seed value in order to guarantee the same sequence of results are returned.
  • #1
hoangr
2
0
Hi,

I was looking into the mathematical aspect of what makes something 'random', but never asked about the programming view. What happens in a random function that generates an output? Although I still haven't found an answer to my question, I've decided to post it here hoping that I could get a clear and informative response (sometimes Google doesn't cut it).

Thanks,
Ryan
 
Technology news on Phys.org
  • #2
A random function depends on the randomizer - usually it is a deterministic series with a very long repeat cycle. That's why you usually need to specify a "seed". For instance, if I use the rand() function in MATLAB for n data points, then repeat it twice, the three sets of results will be identical though they look random within each set.

Fancy systems use some physical method like the 10th decimal place in a sensitive temperature gauge of wind speed or something like that.

In the bad old day we used to use a table of "random numbers" that you could buy. It came as part of a book of tables for all those other things you use a computer for now like sine and cosine and the normal distribution and logs.

Randomizing algorithms are an important part of cryptography.
 
  • #3
Usual random number generators will produce a sequence of numbers (uniformly distributed between 0 and 1) which look random when various statistical tests are applied.
 
  • #4
K&R (the original C programmers' textbook that started me down this dark path) provides this as the source code for rand ()

Code:
unsigned long int next = 1;

int rand(void)
{
    next = next * 1103515245 + 12345;
    return (unsigned int)(next/65536) % 32768;
}

It requires initialisation of the seed value named "next", and will always return the same sequence of random numbers for the same seed value. Hence, usually you initialise this at the start of your program with some "random" value such as the system time (full date and time, obviously).

edit: Being able to set the seed allows for debugging etc, by being able to guarantee the same results are returned.

I note that it doesn't appear to be thread-safe :-) [edit: if your program spawns multiple threads for working concurrently, the value of next is shared by all]

edit: Yes this is not regarded as current code. I know it's bad code. Don't all jump on me! :)
 
Last edited:
  • #5
Wow, thanks for those informative responses! For some reason I didn't even consider seeds being a factor in programming these algorithms.

@rorix_bw: Thanks for the code snippet, I've been looking for the source code in other languages and wasn't successful. :P
 

FAQ: Randomization Question - Get a Clear & Informative Response

What is randomization and why is it important in research?

Randomization is the process of assigning participants to different groups or conditions in a study in a random and unbiased manner. It is important in research because it helps to ensure that the groups being compared are similar in all aspects except for the factor being studied. This allows for more accurate and reliable results.

How is randomization achieved in a study?

Randomization can be achieved through various methods such as using a random number generator, flipping a coin, or drawing names out of a hat. It is important to use a truly random method to avoid any potential biases in the assignment of participants.

Can a study still be valid without randomization?

No, a study without randomization may still provide useful information, but it cannot establish a cause-and-effect relationship. Without randomization, it is difficult to determine whether any observed differences between groups are due to the intervention being studied or other factors.

Are there any disadvantages to using randomization in research?

One potential disadvantage of randomization is that it may result in unequal group sizes, which can impact the statistical power of the study. Additionally, it may not always be feasible or ethical to use randomization, such as in cases where participants have pre-existing conditions that may affect the outcome of the study.

How can randomization be used to minimize bias in research?

Randomization helps to minimize bias in research by ensuring that participants are assigned to groups in an unbiased manner. This helps to reduce the impact of confounding variables and increases the internal validity of the study. Additionally, randomization can also be used in a stratified manner, where participants are grouped based on certain characteristics, to further minimize potential biases.

Back
Top