A common method of producing pseudo-random numbers is by means of the following
ID: 3817805 • Letter: A
Question
A common method of producing pseudo-random numbers is by means of the following recurrence relation: R0 = seed value Ri+1 = (a*Ri + c) % n where Ri denotes the ith pseudo-random number in the stream; a, c, and n are constant integers, and seed value is some initial value provided by the user or chosen automatically by the system. Define a function that returns a stream of random numbers that uses this linear-congruential formula. from operator import add, mul, mod def make_random_stream(seed, a, c, n): """The infinite stream of pseudo-random numbers generated by the recurrence r[0] = SEED, r[i+1] = (r[i] * A + C) % N. Your solution must not use any lambdas or def's that we have not supplied in the skeleton. >>> s = make_random_stream(25, 29, 5, 32) >>> stream_to_list(s, 10) [25, 26, 23, 0, 5, 22, 3, 28, 17, 18] >>> s = make_random_stream(17, 299317, 13, 2**20) >>> stream_to_list(s, 10) [17, 894098, 115783, 383424, 775373, 994174, 941859, 558412, 238793, 718506]
Explanation / Answer
<?
$con = mysql_connect("localhost","inmoti6_myuser","mypassword");
in the event that (!$con)
{
die('Could not interface: " . mysql_error());
}
mysql_select_db("inmoti6_mysite", $con);
$article_id = $_GET['id'];
in the event that( ! is_numeric($article_id) )
die('invalid article id');
$query = "SELECT * FROM `comments` WHERE `articleid` =$article_id LIMIT 0 , 30";
$comments = mysql_query($query);
resound "<h1>User Comments</h1>";
/Please recall that mysql_fetch_array has been expostulated in before
/adaptations of PHP. As of PHP 7.0, it has been supplanted with mysqli_fetch_array.
while($row = mysql_fetch_array($comments, MYSQL_ASSOC))
{
$name = $row['name'];
$email = $row['email'];
$website = $row['website'];
$comment = $row['comment'];
$timestamp = $row['timestamp'];
$name = htmlspecialchars($row['name'],ENT_QUOTES);
$email = htmlspecialchars($row['email'],ENT_QUOTES);
$website = htmlspecialchars($row['website'],ENT_QUOTES);
$comment = htmlspecialchars($row['comment'],ENT_QUOTES);
resound " <div>
Name: $name<br/>
Email: $email<br/>
Site: $website<br/>
Remark: $comment<br/>
Timestamp: $timestamp
</div>
";
}
mysql_close($con);
?>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.