Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

ColdFusion, Random Numbers, and Time

DZone's Guide to

ColdFusion, Random Numbers, and Time

· Java Zone
Free Resource

Microservices! They are everywhere, or at least, the term is. When should you use a microservice architecture? What factors should be considered when making that decision? Do the benefits outweigh the costs? Why is everyone so excited about them, anyway?  Brought to you in partnership with IBM.

A while ago I logged a bug I had discovered with ColdFusion REST services. I had created a simple REST service that returned a random number between one and one hundred. Nothing too complex, right? But then I noticed something odd. If I called the REST service with a cfhttp call twice, I got the same number back. I had discovered - I thought - a serious caching issue with REST services. Turns out I was wrong.

If you read the comments for the bug, you will see one in particular that stands out:

I assume this is one of the engineers, although I don't know. It makes sense - kinda - but I certainly didn't know this and I'm willing to bet most folks aren't aware of this either. As a long time computer programmer, I have a vague idea of the intricacies of random number generation. Apparently it involves quantum states, time travel, and zombie kittens.

The person helping out on the comment thread suggested using IBMSecureRandom as an algorithm for the randRange, but according to the docs this is only supported on WebSphere. I used SHA1PRNG and it worked immediately.

 

Discover how the Watson team is further developing SDKs in Java, Node.js, Python, iOS, and Android to access these services and make programming easy. Brought to you in partnership with IBM.

Topics:

Published at DZone with permission of Raymond Camden, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}