I created a fun utility for employees of my company by which I use the RandRange function in Coldfusion to choose an area restaurant for people standing around wondering where to go for lunch. Believe it or not, it has taken hold and people are using it to choose where to eat at company locations around the country.
The code queries the database for all possible restaurant selections for a given company location. I use the randRange function with the dbQuery.RecordCount value to determine the chosen record number.
Then I loop over the restaurant query comparing the dbQuery.currentRow value to the randomly generated number from earlier. If the currentRow equals the randomly generated number, it is displayed as today's choice. Everything seems to work great with the RandRange function in the scope of a single user / single PC.
Now the issue a co-worker and I discovered recently (and fortunately I'm not using RandRange for any other real purpose):
When we both reload the page at exactly the same time or within milliseconds of each other, we always get the same restaurant on separate PCs on our intranet. This means the Coldfusion server is delivering the same "random" result to different PCs at the same time.
Has anyone else discovered this? Is there a way fix this?
I figured this out and want to share it and hope it helps anyone out there wanting to use the randRange function with multiple users:
Assign the randRange value to a session variable. This will isolate the randRange values between users!