If you want to generate a random number for some business logic you are implementing, what would you do?

You would use Random class if you use Java or C#. Most programming language has some library function or class to give you random number.

But suppose you need to produce random numbers by your own without using any library function what would you do?

There are many algorithms to use to produce random number and here I will demonstrate a very basic algorithm which uses the modulo operator (%) in C#. The goal is not to come up with a foolproof algorithm to generate random numbers, the goal is to just use simple math trick to understand how random numbers can be generated. If you really need to generate random numbers in your programs then you should use the inbuilt library functions provided by the language or framework you are using.

You know what is modulo (%) operator is, right? It gives you the remainder when you divide the left hand number by right hand number.

so doing 20 % 20 will give you 0. And 20 % 19 will give you 1 and 20 % 18 will give to 2 and so on.

You can see when you divide 20 by numbers from 1 to 20 you get number 0 to 9 as remainders. The trick is the larger the dividend, larger the range of number you get as remainders.

So let’s set dividend d to a some large number, for the purpose of this post I will choose 10000. This will give you the range of 0 to 4999 as remainders.

But as you can see, this method produces sequential numbers, not random numbers. Well, on every iteration you use the remainder to produce a new dividend and you can see that instead of sequential numbers you are getting the random numbers.

So, let’s use below equation to produce a new dividend on every iteration, which uses the current remainder as new dividend:

remainder = a * current remainder + b % divisor

Using the above equation, we get below result, when a = 100, b = 100 and divisor is set to 19:

Here, a and b is set to 100 and divisor is set to 12345, while current remainder is initialized to 0 at the start. Note that setting divisor to 12345 did not produce repeated numbers in the first 20 iterations, but it can still produce repeated numbers after few hundred iterations. But you get the idea, right?

The equation a + b * currentRemainder % divisor is called Linear Congruential Generator. You can read more about it here.

When I saw the above in my outlook toolbar I realized that it could help in a lot of productivity gain while managing email.

There are pre-built steps which you can use to manage email as mentioned in the above image. You can add your own quick steps too. Notice that “Archive” on the top-left. I setup that by myself as follows:

Click on the “down arrow” on the left-bottom part (highlighted in blue) of the above screen. A “Manage Quick Steps” dialog box will be opened as below:

Clicking on the “New” button will open up a dialog box as below, where you can setup the action that you want to take. Note that you can also setup a shortcut key which you can use for the action instead of every time selecting the action from the menu.

The above code does a number of things to flatten the code and make it better:

Validations are performed first and it returns at the first opportunity.

Multiple nested conditions are combine into one (with “&&”(logical And) operator. If there are multiple expressions forming one such condition, they can be moved to a separate method returning boolean. That method can then be use in the if condition as below:

In the big sea of web, you will find many people telling you the podcast that every developers should listen. Here is my list, and yes, I too think these are the podcast every developer(.Net developer) should listen.

.Net Rocks: This is more than a decade old talk show focusing on Microsoft .Net Technologies. Earlier it used to be a weekly show, but now it has three show a week. Apart from covering anything and everything related to .Net, it also covers mobile app development on Android and iOS.

HerdingCode: This is a show where discussion goes into nitty-gritty of development tasks. As with the above two, not just the .Net technology, but other aspects of Software development practises are also discussed.

Software Engineering Radio: This is a monthly podcast targeted towards not just .Net developers, but to all software developers in general. So it covers topics which include Software Engineering practises, architecture, design patterns, etc. It also has a rather academic feel and many a times the guests include leading researchers in the field of Computer Science.

MS Dev show: This is relatively a new podcast for Microsoft developers focussing fully to Microsoft technology including topics such as Azure/Cloud, Windows, Windows Phone, .Net etc.

IEEE Software’s Tools of the Trade: This is again the podcast of an on going column in IEEE Software with the same name. In every episode, it covers software tools to be used within a certain aspect of Software Development, such as documentation, debugging, testing, etc.

HBR IdeaCast: This is a weekly podcast from HBR.org and it is mostly about analysis and advice from leading minds in management.

I thought these would be very helpful to those who are learning .Net. J. D. Meier has put up Development Guidance Map for various .Net technologies. This material includes links to technical articles, videos, how-tos, blogs, tutorials, trainings, code samples on various .Net technologies and about everything you might need to know about .net.

In asp.net you might be using lot of hidden variables and ViewState to maintain state between page postbacks. This can make your code look cluttered. You can use properties to encapsulate the hidden fields or ViewState.