vendredi 29 avril 2016

How scrambles the data array with Congruential Linear Generator / Pseudo Random Number Generator

I have data in an array and want to randomize the data in the aray using linear congruiential methods algorithm, without using a php function rand () / shuffle () and functions Functions that already exist.

How should I define variables and using the linear congruential algorithm that? or maybe other pseudo random generator Like Multivicative Random Generator?

my code:

        <?php
        include("koneksi.php");
        $arr = array();
        $q = mysql_query("select * from tbl_soal");
                while ($row = mysql_fetch_assoc($q)) {
                    $temp = array(
                        "soal_id" => $row['id'],
                        "soal"=>$row['soal'],
                        "a"=>$row['a'],
                        "b"=>$row['b'],
                        "c" => $row['c'],
                        "jawaban" => $row['jwaban'],
                        "gambar" => "http://ift.tt/1SPmwqg".$row['gambar'].""
                    );
                    array_push($arr, $temp);
                }   

            //with a random function from php   
            //shuffle($arr);
            //$dd = array_slice($arr, 0, 5);

            $data = json_encode($dd);
            $data = str_replace("\\", "", $data);
            echo "{\"daftar_soal\":" . $data . "}";
        ?>




Aucun commentaire:

Enregistrer un commentaire