if out_of_order_events: randomized_logfile_lines = [] while len(logfile_lines): randomized_logfile_lines.append(logfile_lines.pop(random.randrange(0,len(logfile_lines)))) logfile_lines = randomized_logfile_lines
Tag Archive for random
Password Generator
function randomStr($length) {
$randomStr = "";
$chars = array('2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'm', 'n', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');
while(strlen($randomStr) < $length) {
$alt = rand(1,2) % 2;
if (0 == $alt)
$randomStr .= strtoupper($chars[rand(0, count($chars) - 1)]);
else
$randomStr .= $chars[rand(0, count($chars) - 1)];
}
return $randomStr;
}
$len = (int) 8; // 1 trillion+ is enough doncha think?
if (@strlen($_GET['len']) > 0) {
if (strlen($_GET['len']) > 2)
header('Location:./' . substr(urldecode(addslashes($_GET['len'])), 0, 2));
$len = (int) substr(urldecode(addslashes($_GET['len'])), 0, 2);
}
$password = randomStr($len);
Random Password
function randPassword() {
$password = '';
for ($x = 1; $x <= 8; $x++) {
switch ( rand(1, 3) ) {
// Add a random digit, 0-9
case 1:
$password .= rand(0, 9);
break;
// Add a random upper-case letter
case 2:
$password .= chr( rand(65, 90) );
break;
// Add a random lower-case letter
case 3:
$password .= chr( rand(97, 122) );
break;
}
}
return $password;
}
Random XML Record in Spry using PHP
<script language="JavaScript" type="text/javascript">
<?php $num=rand(1,7); ?>
var ds = new Spry.Data.XMLDataSet("data_in_XML.xml","record/thing[id='<? echo $num; ?>']");
</script>
.
.
.
<div spry:region="ds">
<p spry:repeat="ds"><strong>{ds::title}</strong></p>
<p spry:repeat="ds">{ds::desc}</p>
</div>
Random Range
function randRange( min:Number, max:Number ) : Number
{
return Math.floor(min +(Math.random() * (max- min)));
}
Decimal aleatorio
Public Shared Function DecimalAleatorio(Optional ByVal maximo As Decimal = Decimal.MaxValue, Optional ByVal minimo As Decimal = Decimal.MinValue) As Decimal Dim r As New Random() If minimo > maximo Then Dim t As Decimal = minimo minimo = maximo maximo = t End If lastdecimalvalue = (r.NextDouble() * (maximo - minimo)) + minimo Return lastdecimalvalue
Número aleatorio
Public Shared Function NumeroAleatorio(Optional ByVal maximo As Integer = Integer.MaxValue, Optional ByVal minimo As Integer = Integer.MinValue) As Integer Dim r As New Random(lastintegervalue) If minimo > maximo Then Dim t As Integer = minimo minimo = maximo maximo = t End If lastintegervalue = r.Next(minimo, maximo) Return lastintegervalue End Function
String aleatoreo
Public Shared Function TextoAleatorio(Optional ByVal largoMinimo As Int16 = 1, Optional ByVal largoMaximo As Int16 = Int16.MaxValue) As String Dim i As Integer Dim largo As Integer = NumeroAleatorio(largoMaximo, largoMinimo) Dim strTemp As New StringBuilder(largo) For i = 0 To largo - 1 strTemp.Append(Chr(NumeroAleatorio(maximo:=90, minimo:=65))) Next Return strTemp.ToString() End Function
Random Range
private function randRange(minNum:Number, maxNum:Number):Number
{
return (Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum);
}
Get random record in table
SELECT MAX(id) FROM table <?php $random_num = rand(0, $max(id)); ?> SELECT * FROM table WHERE id >= $random_num LIMIT 1