Home>
-Create a method that returns a random value from the range of the upper limit value and lower limit value as arguments
(However, don't specify an argument to the Random.Next method)
Range random number formula: Minimum value + (int) (Random value * (Maximum value-Minimum value + 1.0)/(1.0 + Maximum random number value))
I was told to do it, but for some reason the minimum value is reflected
Applicable source code
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CS1303_C
{
class Program
{
static void Main (string [] args)
{
Console.Write ("Lower limit:");
int a = int.Parse (Console.ReadLine ());
Console.Write ("Upper limit:");
int b = int.Parse (Console.ReadLine ());
int sum = Add (a, b);
Console.Write (sum);
}
static int Add (int x, int y)
{
Random rnd = new Random ();
int z = rnd.Next (x, y);
int num = x + (int) (z * (y-x + 1.0)/(1.0 + int.MaxValue));
return num;
}
}
} #
I felt that int.MaxValue was wrong, so I checked it and got an error
Supplemental information (FW/tool version etc.)Microsoft VisualStudio2017
-
Answer # 1
-
Answer # 2
int z = rnd.Next (x , y);
If you remove the x and y values of -
Answer # 3
If it is an assignment, it would be helpful to ask the teacher or teacher.
The minimum value is reflected for some reason
That's a little unclear
Related articles
- java - i want to create a method that gets and returns the name corresponding to the number
- c # - [unity] about the type of function that returns multiple types
- [c #] i want to implement a random access file
- c # - i want to create software that manages products on ec sites with macros
- c # - i want to create a collision detection so that the game is over when it hits the picturebox
- a method with a string as an argument in c #
- c # - what kind of method is there to clarify the cause of the exe file, which is neither good nor bad?
- c # i want to pass a value to another method in the same class
- c # - i want to create an older version of an android app with xamarinforms, but i get a build error
- c # - about the naming of the method that checks the input
- c # - what does the error "argumentexception: method return type is incompatible" mean?
- xcode - i want to create a function that returns an address by passing latitude and longitude as arguments!
- c # - [unity 2d] i want to create a gimmick that clings to a rope, hangs, swings like a pendulum, and jumps
- c # - i want to create a prefabricated car (car waypoint based) that runs automatically in unity!
- python 3x - i want to create a function that returns a list with the same name as the argument
- java - to create a method and call it from another class
- typescript - how to create a function that returns a return value (return value) of a specific type (function that determines ou
- i want to create a method in ruby that sums the remainder of array elements
- ruby - i want to create an application that returns constellations
- c++ - create a histogram by the p-tile method and binarize it
Related questions
- c # - get variable values from aspnet code-behind
- unable to add c # systemwindowsformsform
- c # - toolbox is not displayed even on the screen of visual studio design
- c # - it appears in the console window even though it is different from the condition of the unity if statement
- c # - i want to display my form as new after sleeping for a few seconds
- c # - i want to share variables from other scripts
- get audio in c # and display waveform
- c # - i want to specify a different url from the script side for the video player component of unity
- candidates are not displayed even if i hit a period in c # opened in unity
- how do i switch between multiple programs in visual studio c #?