How do I display all 60 numbers

3

How do I display all 60 numbers?

Already random, but only a number.

<?php

class CodeGen {
    private $codes = array();
    public function __construct($codes) {
        $this->codes = $codes;
    }

    public function getRandomCode($min, $max){  
       $next = count($this->codes) + 1; 
       while (count($this->codes) < $next) {
           $code = mt_rand($min, $max); 
           if (!in_array($code, $this->codes)) {            
               $this->codes[] = $code;          
           }        
       }    
    }   

    public function getLastCode(){
        return end($this->codes);   
    }

}

    $codes = array();
    $CodeGen = new CodeGen($codes);
    $CodeGen->getRandomCode(0, 60);
    print $CodeGen->getLastCode();

?>
    
asked by anonymous 02.03.2018 / 18:27

2 answers

3

An array of 60 results:

class CodeGen{
    private $codes = array();
    public function __construct($codes) {
        $this->codes = $codes;
}
    public function getRandomCode($min, $max){  
       $next = 60; 
            while (count($this->codes) < $next) {
                $code = mt_rand($min, $max);    
                if (!in_array($code, $this->codes)) {           
                    $this->codes[] = $code;   
         }      
    }   
}   
    public function getLastCode(){
        return ($this->codes);   
    }
}
    $codes = array();
    $CodeGen = new CodeGen($codes);
    $CodeGen->getRandomCode(0, 60);
    print_r($CodeGen->getLastCode());

Result:

Array ( [0] => 11 [1] => 13 [2] => 48 [3] => 52 [4] => 51 [5] => 54 [6] => 33 [7] => 32 [8] => 38 [9] => 21 [10] => 1 [11] => 18 [12] => 58 [13] => 12 [14] => 2 [15] => 5 [16] => 28 [17] => 50 [18] => 57 [19] => 35 [20] => 7 [21] => 45 [22] => 39 [23] => 43 [24] => 26 [25] => 42 [26] => 29 [27] => 0 [28] => 34 [29] => 20 [30] => 40 [31] => 31 [32] => 46 [33] => 14 [34] => 10 [35] => 19 [36] => 60 [37] => 49 [38] => 23 [39] => 16 [40] => 36 [41] => 47 [42] => 8 [43] => 24 [44] => 22 [45] => 27 [46] => 53 [47] => 44 [48] => 30 [49] => 6 [50] => 17 [51] => 56 [52] => 25 [53] => 55 [54] => 15 [55] => 4 [56] => 3 [57] => 9 [58] => 59 [59] => 41 )
    
02.03.2018 / 19:07
0

You will need to create a get method that will return the $ this- > codes

public function getCodes()
{
    return $this->codes;
}
    
02.03.2018 / 19:01