Highlighted

RandRange not so Rand in Coldfusion MX 7 Standard???

New Here ,
Jul 30, 2018

Copy link to clipboard

Copied

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?

UPDATE ----

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!

Views

127

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

RandRange not so Rand in Coldfusion MX 7 Standard???

New Here ,
Jul 30, 2018

Copy link to clipboard

Copied

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?

UPDATE ----

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!

Views

128

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jul 30, 2018 0

Have something to add?

Join the conversation