How to generate random number using C# and ASP.Net Core



How to generate random number using C# and ASP.Net Core

How to generate random number using C# and ASP.Net Core

How to generate random number using c# and ASP.Net Core
If you want generate random number to create phone active code or other codemixt.RandomNumberHelper package will help you, by package you can generate random number easily.
To explain how to use this package we will Random Number Generator web app
Steps
– Create ASP.Net MVC web app
– Create RandomNumberViewModel class
This class will use to return random number to view, inside class add one property with name RandomNumber and integer data type.
– Open home Controller
In Index action you can create variable with name Number and assign to it the value will coming from RandomNumber.GetNumber() function, you can add length parameter to function to get number of digits you need, create a new instance from RandomNumberViewModel class and assign Number variable to RandomNumber property and return data in view.
– Open Index view
Remove all html content from view, we need to add form with attributes asp action with value Index and asp controller with value Home to submit form and get Random Number, we need to add input with attribute asp-for and its value will be RandomNumber to bind with RandomNumber property, add button to submit form, with value generate.
– Run the project
Now every time you click on Generate button you get a new random number.

Source Code : https://github.com/ahmmedsobh/RandomNumberDemo

I hope this tutorial helped you, and thanks for watching.