本文整理汇总了PHP中Rand函数的典型用法代码示例。如果您正苦于以下问题:PHP Rand函数的具体用法?PHP Rand怎么用?PHP Rand使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Rand函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generate
function generate()
{
$code = base64_encode(chr(Rand(48, 57)) . chr(Rand(65, 90)) . chr(Rand(97, 122)) . chr(Rand(48, 57)) . chr(Rand(65, 90)) . chr(Rand(97, 122)));
mysql_query("INSERT INTO hashcodes (hashcode,timestamp) VALUES('{$code}','" . time() . "')", $this->conn);
$results = mysql_query("SELECT autoid FROM hashcodes WHERE hashcode = '{$code}' LIMIT 0,1");
$autoid = mysql_fetch_array($results);
return $autoid['autoid'];
}
示例2: Generator
public function Generator()
{
$chaine = null;
for ($cpt = 0; $cpt < $this->DIGIT; $cpt++) {
$i = Rand(0, sizeof($this->CARACS) - 1);
$chaine .= $this->CARACS[$i];
}
return $chaine;
}
示例3: insertKey
function insertKey()
{
$objConectar = new conexion();
$conexion = $objConectar->conectar();
$l = time() * 2;
$r = Rand(111, 999);
$llave = $l . $r;
$sql = "INSERT INTO `boobob`.`keys` (`cod`, `idusuario`) VALUES (" . $r . ", " . $this->u->id . ")";
$res = mysql_query($sql, $conexion) or die("Error: " . mysql_error() . "\n" . $sql);
$objConectar->desconectar();
return $r;
}
示例4: generatePassword
function generatePassword()
{
$length = 8;
$upperCase = true;
$specials = true;
$numbers = true;
$generatedPassword = "";
$searchString = "abcdefghijklmnopqrstuvwxyz";
for ($i = 0; $i < $length; $i++) {
$generatedPassword = $generatedPassword . $searchString[Rand(0, strlen($searchString) - 1)];
}
$_SESSION["generatedPassword"] = $generatedPassword;
echo $generatedPassword;
}
示例5: SNAC_Create
function SNAC_Create($FamilyID, $SubTypeID, $Data = '')
{
/****************************************************************************/
$__args_types = array('integer', 'integer', 'string');
#-----------------------------------------------------------------------------
$__args__ = Func_Get_Args();
eval(FUNCTION_INIT);
/****************************************************************************/
$Result = Bytes_I2B(WORD, HexDec($FamilyID)) . Bytes_I2B(WORD, HexDec($SubTypeID)) . Bytes_I2B(BUTE, 0) . Bytes_I2B(BUTE, 0) . Bytes_I2B(DWORD, Rand(1, 65025));
# Номер запроса
#-----------------------------------------------------------------------------
$Result .= $Data;
# Сам пакет
#-----------------------------------------------------------------------------
return $Result;
}
示例6: createNumber
function createNumber()
{
$n1 = Rand(1, 49);
do {
$n2 = Rand(1, 49);
} while ($n2 == $n1);
do {
$n3 = Rand(1, 49);
} while ($n3 == $n2 || $n3 == $n1);
do {
$n4 = Rand(1, 49);
} while ($n4 == $n3 || $n4 == $n2 || $n4 == $n1);
do {
$n5 = Rand(1, 49);
} while ($n5 == $n4 || $n5 == $n3 || $n5 == $n2 || $n5 == $n1);
$str = "{$n1} {$n2} {$n3} {$n4} {$n5}";
$str .= " mega: " . Rand(1, 27) . "<br>";
echo $str;
}
示例7: gException
case 'error':
return ERROR | @Trigger_Error(500);
case 'exception':
return new gException('POSTINGS_NOT_FOUND', 'Операции по договору не найдены');
case 'array':
break;
default:
return ERROR | @Trigger_Error(101);
}
#-------------------------------------------------------------------------------
foreach ($WorksComplite as $WorkComplite) {
#-------------------------------------------------------------------------------
$CreateDate = $WorkComplite['CreateDate'];
#-------------------------------------------------------------------------------
if (isset($Verifies[$CreateDate])) {
$CreateDate += Rand(1, 100) / 100;
}
#-------------------------------------------------------------------------------
$Comp = Comp_Load('Formats/Percent', $WorkComplite['Discont']);
if (Is_Error($Comp)) {
return ERROR | @Trigger_Error(500);
}
#-------------------------------------------------------------------------------
$Cost = Comp_Load('Formats/Currency', $WorkComplite['Cost']);
if (Is_Error($Cost)) {
return ERROR | @Trigger_Error(500);
}
#-------------------------------------------------------------------------------
$Verifies[$CreateDate] = array('Founding' => SPrintF('%s %s', $WorkComplite['Service'], $WorkComplite['Comment']), 'Measure' => $WorkComplite['Measure'], 'Amount' => (int) $WorkComplite['Amount'], 'Cost' => $Cost, 'Discont' => $Comp, 'Debet' => 0, 'Credit' => $WorkComplite['Summ']);
#-------------------------------------------------------------------------------
}
示例8: mysqli_connect
<?php
//EDIT THIS
$mysqlserver = 'localhost';
//Server - Normally Localhost
$username = 'username';
//Database Username
$password = 'password';
//Database Password
$database = 'quotes';
//Default of mysql import
//If you do not know what your doing, do not touch!
$con = mysqli_connect("{$mysqlserver}", "{$username}", "{$password}", "{$database}");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$num = Rand(0, 2);
$result = mysqli_query($con, "SELECT * FROM quotes ORDER BY RAND() LIMIT 1");
while ($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['quote'] . "</td>";
echo "</tr>";
}
?>
示例9: srand
default:
$title = "No Admin type selected";
include "header.php";
print "You did not enter an Admin Type. Please use the back button and try again.";
include "footer.php";
exit;
}
/* Since we've gotten this far in this if routine (i.e. the script hasn't exited),
the user must have entered the correct Admin password. So, we can create the cookie
and AdminAuthorization table entry */
srand(time());
$Pool = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$Pool .= "abcdefghijklmnopqrstuvwxyz";
$AuthorizationCode = "";
for ($index = 0; $index < 12; $index++) {
$AuthorizationCode .= substr($Pool, Rand() % strlen($Pool), 1);
}
$LoginTime = date('YmdHis');
/* Do the insert into the database first, so that the cookie will not be set if the
input fails */
if (!mysql_query("INSERT INTO adminlogins\r\n \t\t VALUES({$MemberID},'{$AuthorizationCode}',{$LoginTime},'{$AdminType}')")) {
$title = "Error in authorization process";
include "header.php";
print "The system was unable to register your authorization information. The database returned the following message: <p>\n";
print mysql_error();
include "footer.php";
exit;
}
/* Made it. Set the cookies. */
SetCookie("AuthorizationCode", $AuthorizationCode, time() + 7200);
SetCookie("LoginTime", $LoginTime, time() + 7200);
示例10: Rand
<center>
<?php
//Select random number form 1 to 50
$num = Rand(1, 50);
//Based on the random number, gives a quote
switch ($num) {
case 1:
echo "<b>Things work out best for those who make the best of how things work out.</b><BR> <h3 style='color:#782492;padding-top:5px'><b>John Wooden</b></h3>";
break;
case 2:
echo "<b>Dream Dream Dream, Dreams transform into thoughts and thoughts result in action.</b><BR><h3 style='color:#782492;padding-top:5px'><b>Dr. Abdul Kalam</b></h3>";
break;
case 3:
echo "<b>To live a creative life, we must lose our fear of being wrong.</b><BR> <b><h3 style='color:#782492;padding-top:5px'>Anonymous</b></h3>";
break;
case 4:
echo "<b>If you are not willing to risk the usual you will have to settle for the ordinary.</b><BR> <b><h3 style='color:#782492;padding-top:5px'>Jim Rohn</b></h3>";
break;
case 5:
echo "<b>Trust because you are willing to accept the risk, not because it's safe or certain.</b><BR><h3 style='color:#782492;padding-top:5px'><b>Anonymous</b></h3>";
break;
case 6:
echo "<b>Take up one idea. Make that one idea your life--think of it, dream of it, live on that idea. Let the brain, muscles, nerves, every part of your body, be full of that idea, and just leave every other idea alone. This is the way to success.</b><BR><h3 style='color:#782492;padding-top:5px'><b>Swami Vivekananda</b></h3>";
break;
case 7:
echo "<b>All our dreams can come true if we have the courage to pursue them.</b><BR><h3 style='color:#782492;padding-top:5px'><b>Walt Disney</b></h3>";
break;
case 8:
echo "<b>Good things come to people who wait, but better things come to those who go out and get them.</b><BR><h3 style='color:#782492;padding-top:5px'><b>Anonymous</b></h3>";
break;
case 9:
示例11: array
}
#-------------------------------------------------------------------------------
$Config = $XML->ToArray();
#-------------------------------------------------------------------------------
$Config = $Config['XML'];
#-------------------------------------------------------------------------------
} else {
#-------------------------------------------------------------------------------
$Config = array();
#-------------------------------------------------------------------------------
}
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
if (!isset($Config['CSRFKey']) || !$Config['CSRFKey']) {
#-------------------------------------------------------------------------------
$Config['CSRFKey'] = Str_Shuffle(Md5(MicroTime() . Rand(0, 1000000)));
#-------------------------------------------------------------------------------
}
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
if (isset($Config['Interface']['Notes'])) {
unset($Config['Interface']['Notes']);
}
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
if (isset($Config['Other']['Libs']['Http'])) {
unset($Config['Other']['Libs']['Http']);
}
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
if (isset($Config['Users']['Register'])) {
示例12: auditTrail
}
// Uprava symbolu
if (isset($_POST['symbolid']) && isset($_POST['editsymbol']) && $usrinfo['right_text']) {
auditTrail(7, 2, $_POST['symbolid']);
pageStart('Uložení změn');
mainMenu(5);
if (!isset($_POST['notnew'])) {
unreadRecords(7, $_POST['symbolid']);
}
sparklets('<a href="./symbols.php">symboly</a> » <a href="./editsymbol.php?rid=' . $_POST['symbolid'] . '">úprava symbolu</a> » <strong>uložení změn</strong>', '<a href="./readsymbol.php?rid=' . $_POST['symbolid'] . '">zobrazit upravené</a>');
if (is_uploaded_file($_FILES['symbol']['tmp_name'])) {
$sps = MySQL_Query("SELECT symbol FROM " . DB_PREFIX . "symbols WHERE id=" . $_POST['symbolid']);
if ($spc = MySQL_Fetch_Assoc($sps)) {
unlink('./files/symbols/' . $spc['symbol']);
}
$sfile = Time() . MD5(uniqid(Time() . Rand()));
move_uploaded_file($_FILES['symbol']['tmp_name'], './files/' . $sfile . 'tmp');
$sdst = resize_Image('./files/' . $sfile . 'tmp', 100, 100);
imagejpeg($sdst, './files/symbols/' . $sfile);
unlink('./files/' . $sfile . 'tmp');
MySQL_Query("UPDATE " . DB_PREFIX . "symbols SET symbol='" . $sfile . "' WHERE id=" . $_POST['symbolid']);
}
if ($usrinfo['right_org'] == 1) {
$sql = "UPDATE " . DB_PREFIX . "symbols SET `desc`='" . mysql_real_escape_string($_POST['desc']) . "', archiv='" . (isset($_POST['archiv']) ? '1' : '0') . "', search_lines='" . $_POST['liner'] . "', search_curves='" . $_POST['curver'] . "', search_points='" . $_POST['pointer'] . "', search_geometricals='" . $_POST['geometrical'] . "', search_alphabets='" . $_POST['alphabeter'] . "', search_specialchars='" . $_POST['specialchar'] . "' WHERE id=" . $_POST['symbolid'];
MySQL_Query($sql);
} else {
$sql = "UPDATE " . DB_PREFIX . "symbols SET `desc`='" . mysql_real_escape_string($_POST['desc']) . "', modified='" . Time() . "', modified_by='" . $usrinfo['id'] . "', archiv='" . (isset($_POST['archiv']) ? '1' : '0') . "', search_lines='" . $_POST['liner'] . "', search_curves='" . $_POST['curver'] . "', search_points='" . $_POST['pointer'] . "', search_geometricals='" . $_POST['geometrical'] . "', search_alphabets='" . $_POST['alphabeter'] . "', search_specialchars='" . $_POST['specialchar'] . "' WHERE id=" . $_POST['symbolid'];
MySQL_Query($sql);
}
echo '<div id="obsah"><p>Symbol upraven.</p></div>';
pageEnd();
示例13: _taskUpdate
private function _taskUpdate()
{
foreach ($this->_devices as $mac => $device) {
if ($device["type"] != "Plugwise(USBStick)") {
$now = time();
if ($device["powerrequest"] == NULL) {
$lastrequest = $now - $this->_pollPower - 1;
//writelog ("Task Update : $mac - set last request");
} else {
$lastrequest = strtotime($device["powerrequest"]);
//writelog ("Task Update : $mac - set last request");
}
$diffrequest = $now - $lastrequest + Rand(-2, 2);
if ($device["powercontact"] == NULL && $diffrequest > $this->_pollPower) {
writelog($this->_process . " : TaskUpdate : {$mac} - Force update power");
$this->_devices[$mac]["powerrequest"] = $this->_now();
$this->_requestDevicePowerInfo($mac);
} elseif ($device["powercontact"] !== NULL) {
$lastupdate = strtotime($device["powercontact"]);
$diffcontact = $now - $lastupdate;
if ($diffcontact > $this->_pollPower && $diffrequest > $this->_pollPower) {
writelog($this->_process . " : TaskUpdate : {$mac} - Need update power");
$this->_requestDevicePowerInfo($mac);
$this->_devices[$mac]["powerrequest"] = $this->_now();
}
}
if ($device["inforequest"] == NULL) {
$lastrequest = $now - $this->_pollInfo - 1;
} else {
$lastrequest = strtotime($device["inforequest"]);
}
$diffrequest = $now - $lastrequest + Rand(-2, 2);
if ($device["infocontact"] == NULL && $diffrequest > $this->_pollInfo) {
$this->_devices[$mac]["inforequest"] = $this->_now();
$this->_requestDeviceInfo($mac);
} elseif ($device["infocontact"] !== NULL) {
$lastupdate = strtotime($device["infocontact"]);
$diffcontact = $now - $lastupdate;
if ($diffcontact > $this->_pollInfo && $diffrequest > $this->_pollInfo) {
writelog($this->_process . " : TaskUpdate : {$mac} - Need update info");
$this->_requestDeviceInfo($mac);
$this->_devices[$mac]["inforequest"] = $this->_now();
}
}
/*--------------------------------------------------------------
* Clock Update
*------------------------------------------------------------*/
if ($device["clockrequest"] == NULL) {
$lastrequest = $now - $this->_pollClock - 1;
} else {
$lastrequest = strtotime($device["clockrequest"]);
}
$diffrequest = $now - $lastrequest + Rand(-2, 2);
if ($device["clockcontact"] == NULL && $diffrequest > $this->_pollClock) {
writelog($this->_process . " : TaskUpdate : {$mac} - Force clock update");
$this->_requestClockSet($mac);
$this->_devices[$mac]["clockrequest"] = $this->_now();
} elseif ($device["clockcontact"] !== NULL) {
$lastupdate = strtotime($device["clockcontact"]);
$diffcontact = $now - $lastupdate;
if ($diffcontact > $this->_pollClock && $diffrequest > $this->_pollClock) {
writelog($this->_process . " : TaskUpdate : {$mac} - Need clock update");
$this->_requestClockSet($mac);
$this->_devices[$mac]["clockrequest"] = $this->_now();
}
}
}
}
}
示例14: date
$m = date("M");
echo "The goal for this month is to review the {$goal[$m]} site!<br>";
echo "<hr size='1'>";
echo "TV List: ";
$site = array("hbo", "cnn", "cbs", "abc", "nbc", "fox", "tnt", "tbs", "mtv");
foreach ($site as $key => $url) {
echo "<a href=\"http://www.{$url}.com\">{$url}</a> | ";
}
echo "<hr size = '1'>";
$x;
//declare array
for ($i = 0; $i < 50; $i++) {
$x[$i] = $i + 1;
}
echo "Original list: <br>";
for ($i = 0; $i < sizeof($x); $i++) {
echo $x[$i] . " ";
}
echo "<br>Shuffled list: <br>";
$size = sizeof($x);
$last = $size - 1;
for ($j = 0; $j < $last; $j++) {
$r = Rand(0, $size - 1);
$temp = $x[$r];
$x[$r] = $x[$last];
$x[$last] = $temp;
$last--;
}
for ($i = 0; $i < sizeof($x); $i++) {
echo $x[$i] . " ";
}
示例15: SaveVcard
public function SaveVcard($randName = false)
{
if ($randName) {
$this->fileName = $this->fileName . uniqid(MD5(Rand(00, 9999999)));
}
$handel = @fopen($this->saveTo . "/" . $this->fileName . ".vcf", "w");
$write = @fwrite($handel, $this->vcard, strlen($this->vcard));
@fclose($handel);
return $write ? true : false;
}