This article describes the method of generating random number in C# and js. Share it for your reference. The details are as follows:
1. C# generates random numbers method:
(low,high);
Description: Generate random numbers of 70-100
(70,100);
2. js random number method:
Description: Generate random numbers of 80-100
Method 1:
{
var Range = Max - Min;
var Rand = ();
return(Min + (Rand * Range));
}
var num = GetRandomNum(1,10);
alert(num);
Method 2:
function generateMixed(n) {
var res = "";
for(var i = 0; i < n ; i ++) {
var id = (()*35);
res += chars[id];
}
return res;
}
Replenish:
(); The result is a random number between 0-1 (including 0, not 1)
(num); The parameter num is a numeric value, and the result of the function is the integer part of num.
(num); The parameter num is a numeric value, and the result of the function is an integer rounded by num.
: Mathematical object, providing mathematical calculations of data.
(); Returns a random number between 0 and 1 (including 0, not 1).
(n); Returns the smallest integer greater than or equal to n.
When using (()*10);, it mainly obtains random integers from 1 to 10, and the probability of getting 0 is extremely small.
(n); Returns the value of the integer after n rounds.
Use (()); to obtain random integers from 0 to 1 evenly.
When using (()*10);, you can basically obtain random integers from 0 to 10, and the probability of getting the minimum value 0 and maximum value 10 is half the less.
(n); Returns the maximum integer less than or equal to n.
When using (()*10);, random integers from 0 to 9 can be obtained evenly.
I hope this article will be helpful to everyone's C# programming.