Home > Backend Development > PHP Tutorial > Simple random lottery function written in php

Simple random lottery function written in php

WBOY
Release: 2016-07-25 08:43:09
Original
1503 people have browsed it
  1. /**
  2. * "Lottery" function
  3. *
  4. * @param integer $first starting number
  5. * @param integer $last ending number
  6. * @param integer $total number of winners
  7. *
  8. * @return string
  9. *
  10. */
  11. function isWinner($first, $last, $total)
  12. {
  13. $winner = array();
  14. for ($i=0;;$ i++)
  15. {
  16. $number = rand($first, $last);
  17. if (!in_array($number, $winner))
  18. $winner[] = $number; // If the number is not in the array, replace it Add to array
  19. if (count($winner) == $total) break;
  20. }
  21. return implode(' ', $winner);
  22. }
  23. // for test
  24. echo isWinner(1, 100, 30);
Copy code

php


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template