Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]Losowanie liczb losowych (zwiększanych o min 100)
max_mcee
post 6.10.2017, 08:18:23
Post #1





Grupa: Zarejestrowani
Postów: 156
Pomógł: 1
Dołączył: 25.09.2007

Ostrzeżenie: (0%)
-----


Mam skrypt który generuje liczby z przedziału 100000 - 999999.
  1. <?php
  2. function random_numbers ($from, $to, $amount) {
  3. $range = range($from, $to);
  4. $random = array_rand($range, $amount);
  5. $result = array();
  6. if (is_array($random)) {
  7. foreach ($random as $index) {
  8. $result []= $range[$index];
  9. }
  10. } else {
  11. $result []= $range[$random];
  12. }
  13. return $result;
  14. }
  15. print_r (random_numbers(100000, 999999, 5000));
  16. ?>

Potrzebuje aby jedna liczba od drugiej różniła się o minimum 100. Jak można by to dobudować?
Dziękuję za pomoc.
Go to the top of the page
+Quote Post
viking
post 6.10.2017, 08:31:11
Post #2





Grupa: Zarejestrowani
Postów: 6 378
Pomógł: 1116
Dołączył: 30.08.2006

Ostrzeżenie: (0%)
-----


Poczytaj sobie dokładnie definicję funkcji http://php.net/manual/en/function.range.php 3 parametr


--------------------
Go to the top of the page
+Quote Post
Pyton_000
post 6.10.2017, 08:53:20
Post #3





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

Ostrzeżenie: (0%)
-----


@viking A co mu to da smile.gif

Go to the top of the page
+Quote Post
max_mcee
post 6.10.2017, 09:27:13
Post #4





Grupa: Zarejestrowani
Postów: 156
Pomógł: 1
Dołączył: 25.09.2007

Ostrzeżenie: (0%)
-----


Cytat(viking @ 6.10.2017, 09:31:11 ) *
Poczytaj sobie dokładnie definicję funkcji http://php.net/manual/en/function.range.php 3 parametr


Umiejętność czytania ze zrozumieniem smile.gif DZIĘKUJĘ
  1. function random_numbers ($from, $to, $amount, $compa, $compb) {
  2. $moose = rand($compa,$compb);
  3. $range = range($from, $to, $moose);
  4. $random = array_rand($range, $amount);
  5. $result = array();
  6. if (is_array($random)) {
  7. foreach ($random as $index) {
  8. $result []= $range[$index];
  9. }
  10. } else {
  11. $result []= $range[$random];
  12. }
  13. return $result;
  14. }
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 15.07.2025 - 00:00