Last active
February 26, 2019 00:45
-
-
Save dsaouda/53b86785ebc06294af2e343d6bf4fa64 to your computer and use it in GitHub Desktop.
Gerador de números da sorte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Threading.Tasks; | |
using Microsoft.AspNetCore.Mvc; | |
namespace Dotnet.No.Linux.Controllers | |
{ | |
[Route("api/[controller]")] | |
[ApiController] | |
public class ValuesController : ControllerBase | |
{ | |
[HttpGet] | |
public ActionResult<IEnumerable<int>> Get(int inicio = 1, int fim = 10, int total = 6) | |
{ | |
if (inicio >= fim) | |
{ | |
return BadRequest("inicio deve ser menor que fim"); | |
} | |
if (total <= 0) | |
{ | |
return BadRequest("total não deve ser menor ou igual a zero"); | |
} | |
var numeros = new HashSet<int>(); | |
while(numeros.Count() != total) | |
{ | |
numeros.Add(new Random().Next(inicio, fim)); | |
} | |
return numeros; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment