The African Globalist touches on issues brought about by the convergence of technology, open markets and global business strategy. It also chronicles lessons learned on an ongoing projects including a web-based content management system in PHP, ASP.Net development and Microsoft Office SharePoint Server

Creating a Random Number Between a Specified Range of Numbers

There are times when you want to generate a random number that is between a certain range, for example, between ‘x’ and ‘y’ where ‘y’ is larger than ‘x’. Many coding languages will have a random number generator and so creating a random number in theory using the native built in language function is not a problem. However, in many cases, this random number generator will create a random number between 0 and 1 and so in most cases, this is not a format which you will find useful because you would be looking for a random number between ‘x’ and ‘y’ and so you must convert this random number to fit in this range.

The way to go about doing this is actually rather simple.

Required Number = (Random Number * (MaxRange - MinRange) + MinRange

Leave a Reply