function gauss() { // auxilary vars $x = random_0_1(); $y = random_0_1(); // two independent variables with normal distribution N(0,1) $u = sqrt(-2 * log($x)) * cos(2 * pi() * $y); return $u; }
echo true; } else { echo false; } mysqli_query($conn, $add); } else { file_put_contents($debug_log, $errormsg); } mysqli_close($conn); } else { if ($postType == "reply") { $conn = new mysqli("localhost", "user", "password", "Submissions_db"); $body = mysqli_real_escape_string($conn, $_POST['body']); $userid = mysqli_real_escape_string($conn, $_POST['userid']); $postid = mysqli_real_escape_string($conn, $_POST['postid']); $replyid = idGenerator(7); $query = "SELECT * FROM replyUsernames_tbl WHERE postid = '" . $postid . "' AND userid = '" . $userid . "';"; mysqli_query($conn, $query); $n = mysqli_affected_rows($conn); file_put_contents("file_debug.txt", $n); if ($n <= 0) { $add = "INSERT INTO replyUsernames_tbl (postid, userid, name, color)\n\t\t\t\t\tVALUES('" . $postid . "', '" . $userid . "', '" . nameGenerator() . "', '" . random_0_1() . "," . random_0_1() . "," . random_0_1() . "');"; mysqli_query($conn, $add); } if ($submitOK == true) { $add = "INSERT INTO replies_tbl (body, votes, userid, postid, replyid, timestamp, IP_client, IP_server)\n\t\t\t\t\tVALUES('" . $body . "', 0, '" . $userid . "', '" . $postid . "', '" . $replyid . "', " . time() . ", '" . $_SERVER['REMOTE_ADDR'] . "', '" . $_SERVER['HTTP_X_FORWARDED_FOR'] . "');"; mysqli_query($conn, $add); } mysqli_close($conn); } }
function random_gauss() { // N(0,1) // returns random number with normal distribution: // mean=0 // std dev=1 // auxilary vars $x = random_0_1(); $y = random_0_1(); // two independent variables with normal distribution N(0,1) $u = sqrt(-2 * log($x)) * cos(2 * pi() * $y); $v = sqrt(-2 * log($x)) * sin(2 * pi() * $y); // i will return only one, couse only one needed return $u; }