ksg - 1 year ago 183

C# Question

I want to generate an unique 4 digit random number. This is the below code what I have tried

**Code for generating random no**

`//Generate RandomNo`

public int GenerateRandomNo()

{

int _min = 0000;

int _max = 9999;

Random _rdm = new Random();

return _rdm.Next(_min, _max);

}

The problem is I have received a random no with value

`241`

Any help will be highly appreciated.

Answer Source

```
//Generate RandomNo
public int GenerateRandomNo()
{
int _min = 1000;
int _max = 9999;
Random _rdm = new Random();
return _rdm.Next(_min, _max);
}
```

you need a 4 digit code, start with 1000