# Computer Science

• August 7th 2009, 12:17 PM
Media_Man
Computer Science
Hi everybody. I am looking for the simplest way to generate "random" numbers given nonrandom input, except I need the output to always be the same, given the same input.

This is a simplification of what I am really doing as part of a website. I want to feature a certain random article as the "Article of the Day." Each day it must change at random. But during the day, one user logging on two different times must see the same one. And two users logging in on the same day must see the same one. I know I can hardcode a list, but I want the algorithm to update itself automatically, and throw new articles in the selection pool as they are added by users (only at the end of each day, though).

I know the function $f(x)=kx(1-x)$ behaves chaotically when k is between 3 and 4. So an example algorithm might be letting k=3.98 and taking the (N+100)th iteration of the number .5, where N represents the day of the year (1-366). The answer, A, would then be a number between 0 and 1, so A times the number of articles saved in the system would return a whole number that tags a random article.

There are some technical problems with this particular function, and I fear it is overkill. Are there any standard ways of doing what I am describing?
• August 7th 2009, 12:20 PM
CaptainBlack
Quote:

Originally Posted by Media_Man
Hi everybody. I am looking for the simplest way to generate "random" numbers given nonrandom input, except I need the output to always be the same, given the same input.

This is a simplification of what I am really doing as part of a website. I want to feature a certain random article as the "Article of the Day." Each day it must change at random. But during the day, one user logging on two different times must see the same one. And two users logging in on the same day must see the same one. I know I can hardcode a list, but I want the algorithm to update itself automatically, and throw new articles in the selection pool as they are added by users (only at the end of each day, though).

I know the function $f(x)=kx(1-x)$ behaves chaotically when k is between 3 and 4. So an example algorithm might be letting k=3.98 and taking the (N+100)th iteration of the number .5, where N represents the day of the year (1-366). The answer, A, would then be a number between 0 and 1, so A times the number of articles saved in the system would return a whole number that tags a random article.

There are some technical problems with this particular function, and I fear it is overkill. Are there any standard ways of doing what I am describing?

Does the language not support a pseudo random number generator, if so use that. Failing that look at volume 2 of Don Knuth's TAOCP "Semi-Numerical Algorithms"

CB

CB
• August 7th 2009, 06:06 PM
alunw
You might like to visit this web site: Random Number Generators - the pLab project - Home and especially this page
A collection of classical pseudorandom number generators with linear structures - advanced version
The first Hoaglin LCG is very easy to implement and works very well for me (in some code I wrote that draws fractals using random iteration this random number generator produced far better results than the one in the C library). But for your problem I'd probably calculate a day number from the date and multiply it by some moderately sized prime number and mod it by the number of articles.