Random()

The same technique can be used to implement the Random() method as well:

/// <summary>
/// GET: api/quiz/mostViewed
/// Retrieves the {num} random Quizzes
/// </summary>
/// <param name="num">the number of quizzes to retrieve</param>
/// <returns>{num} random Quizzes</returns>
[HttpGet("Random/{num:int?}")]
public IActionResult Random(int num = 10)
{
var sampleQuizzes = ((JsonResult)Latest(num)).Value
as List<QuizViewModel>;

return new JsonResult(
sampleQuizzes.OrderBy(t => Guid.NewGuid()),
new JsonSerializerSettings()
{
Formatting = Formatting.Indented
});
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.181.36