Skip to content

Instantly share code, notes, and snippets.

@dsaouda
Last active February 26, 2019 00:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsaouda/53b86785ebc06294af2e343d6bf4fa64 to your computer and use it in GitHub Desktop.
Save dsaouda/53b86785ebc06294af2e343d6bf4fa64 to your computer and use it in GitHub Desktop.
Gerador de números da sorte
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