Pierreszwk Pierreszwk - 11 months ago 51
C# Question

Return random number 2 value (min max) c#

I need your help.
i would like to display a random number between two different value of an url parameters.

This is the code. It doesn't work

public class RandomIntController : ApiController
public double Get()
double min = Request.QueryString("min");
double max = Request.QueryString("max");
min = 1;
max = 100;

Random number = new Random();
return number.NextDouble();

So for exemple the guest insert this url :

My web api must display a random number between the max value(23) and the min value(12).

I have also several error with the attribut 'resquest.queryString()' :/


I don't found my error so please help me

Thank's a lot

Answer Source
int min = (int)Request.QueryString["min"];
int max = (int)Request.QueryString["max"];
Random number = new Random();
return number.Next(min, max);

QueryString is a key value pair, not method. use [] instead of (). Also pass min and max as a parameter to Next method as in code.