Public
snipts » random
showing 1-17 of 17 snipts for random
-
∞ random md5
md5(uniqid(rand(), true)); -
∞ Load random mp3's to mp3 player
#!usr/bin/perl -w # http://ubuntuforums.org/attachment.php?attachmentid=17255&d=1160475724 # http://ubuntuforums.org/showthread.php?t=216102 ###################################################################################### # Author : Jan Roald Haugland janroald@gmail.com # ###################################################################################### # No effort is made to make this a good script :-) # # Free to use, free to modify # # If something goes to hell; dont blame me. No guarantees provided... # ###################################################################################### ###################################################################################### # Syntax : # # perl copyrandom.pl [source directory] [destination] ([max megabytes to transfer])# # Example : # # perl copyrandom.pl /home/you/mp3/ /media/ipod/ 500 # ###################################################################################### #500 is MB's you want to transfer (maximum). This is also default if u dont specify # ###################################################################################### ###################################################################################### # Config ############################################################################# # Add or remove extesions to be transferred here, separate with comma $extensions_allowed = 'mp3,ogg,wma'; # Edit number of megabytes to be transferred if not specified as argument $default_mb = 500; # Only edit below if u know what u are doing ###################################################################################### ###################################################################################### # Parameters ######################################################################### $source = $ARGV[0]; if($source !~ m/\/$/) { $source = $source.'/'; } $destination = $ARGV[1]; $max_mb = (!$ARGV[2]?$default_mb:$ARGV[2]); $extensions_allowed =~ s/,/|/g; # Other variables #################################################################### my $mb_total = 0; #Start counting my $file = ''; my @list = (); my @files = (); my %files_test = (); my $dir = ''; ###################################################################################### print "\n--- Looking for songs in $source ... ---\n\n"; print "--- Copying maximum ${max_mb}MB's to $destination... ---\n\n"; # Using shell 'ls' to list all files and directories @list = `ls -1pshR $source`; splice(@list, 0, 1); # Looping through the list, selecting directories and songs # Generating songlist with trailing megabytes $x = 0; foreach(@list) { if($_ =~ /^\.\/(.*):$/) { $dir = "$1/"; $dir =~ s/([\s\(\)!&'"`\[\],\|:])/\\$1/g; } if($_ =~ /^$source(.*):$/) { $dir = "$1/"; $dir =~ s/([\s\(\)!&'"`\[\],\|:])/\\$1/g; } if( $_ =~ /^\s?([\d|\.]*)M\s((.*)\.($extensions_allowed))$/i ) { $file = $2; $mb = $1; $file =~ s/([\s\(\)!&'"`\[\],\|:])/\\$1/g; push(@files, "$dir$file|$mb"); } $x++; } # Picking out random files and copying to destination. Making same song isn't copied twice $number_of_files = @files; while($max_mb > $mb_total) { $random = rand($number_of_files); ($song,$size) = split('\|',$files[$random]); if(!$files_test{$song}) { $mb_total+=$size; $files_test{$song} = 1; if($max_mb > $mb_total) { `cp $source$song $destination`; print "### Transferred file $song ### ${size}MB's ### ${mb_total}MB's total ###\n"; } } } -
∞ Random alphabetical and numerical strings
<?php function randomString($max) { $alfabet = "abcdefghijklmnopqrstuvwxyz"; $paraula = ""; for($i=0;$i<$max;$i++) { $paraula .= $alfabet[floor(rand(0,25))]; } return $paraula; } function randomInt($max) { $numeros = "1234567890"; $paraula = ""; for($i=0;$i<$max;$i++) { $paraula .= $numeros[floor(rand(0,9))]; } } ?>
-
∞ Random Name Generator
#include <iostream> #include <ctime> #include <string> using namespace std; int main() { srand(time(0)); char gName; string firstname[] = {"John", "Tim", "Andy", "Ronald", "Aaron", "Michael", "Tony", "Hardy", "Harry", "Ron"}; string lastname[] = {"Roberts", "Kennedy", "Alonso", "Gates", "Norman", "Fields", "Potter", "Carter", "Jackson", "Thomas"}; do { cout << "Random Name Generated: " << firstname[rand() % 10] << " " << lastname[rand() % 10] << endl; cout << "Generate another name?(Y/N) "; cin >> gName; cout << endl; }while((gName == 'Y') || (gName == 'y')); return 0; }
-
∞ random number as3
var ran:int = Math.round(Math.random() * (high - low)) + low;
-
∞ RandWall
#!/bin/bash # # randwall # # Muda de papel de parede em OpenBox e derivados. # Com base em um diretório pré-determinado ou com # base em um parametro passado pelo usuário. if [ "$1" ]; then WALLPAPERS=$1 else WALLPAPERS=$HOME/img/wallpapers fi if [ ! -d $WALLPAPERS ]; then echo "Invalid directory." exit 0 fi LISTA=( `ls -w1 "$WALLPAPERS"` ) FAIXA=${#LISTA[*]} MOSTRA=$(( $RANDOM % $FAIXA )) if [ -f $WALLPAPERS/${LISTA[$MOSTRA]} ]; then nitrogen --set-centered "$WALLPAPERS/${LISTA[$MOSTRA]}" else echo "$WALLPAPERS/${LISTA[$MOSTRA]} is not a valid file." fi
-
∞ javascript random string function
function rnd(){ return String((new Date()).getTime()).replace(/\D/gi,'') }
-
∞ Random string
<?php $chars = array_merge(range('a', 'z'), range('A', 'Z'), range(0, 9)); $len = 16; $output = ''; for ($x = 0; $x < $len; $x++) $output .= $chars[array_rand($chars)]; echo $output; ?>
-
∞ Simple generation of random string in Python
import string import random print "".join(random.sample(string.letters+string.digits, 8))
-
∞ Text Munger: flips all the letters but the first and last into a random order.
<?php error_reporting(0); function shuffleAd ($word) { $firstLetter = substr ($word, 0, 1); $word = substr_replace($word, "", 0, 1); $lastLetter = substr ($word, (strlen($word)-1), 1); $word = str_shuffle(substr_replace($word, "", (strlen($word)-1), 1)); return "$firstLetter$word$lastLetter "; } if ($_POST["submit"]) { $text = $_POST['text']; echo "<form id=\"form\" name=\"form\" action=\"munger2.php\" method=\"post\"><input type=\"text\" id=\"text\" name=\"text\" /><input type=\"submit\" id=\"submit\" value=\"Add!\" name=\"submit\" /></form>"; $array1 = explode(" ", $text); //put string into an array, divided by spaces $arraySize = count($array1); for ($i = 0 ; $i < $arraySize ; $i++) //for each word I type print stripslashes(shuffleAd($array1[$i])); } else { echo "<form id=\"form\" name=\"form\" action=\"munger2.php\" method=\"post\"><input type=\"text\" id=\"text\" name=\"text\" /><input type=\"submit\" id=\"submit\" value=\"Spin Around!\" name=\"submit\" /></form>"; } ?>
-
∞ Lua random thing
str = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890" for i = 0,#str do i = i + 1 io.write(string.sub(str,i,i)) end
-
∞ Simulador de moneda
/* Programa que simula lanzamiento de moneda // Yamil Gonzales // Programación I */ #include <iostream> #include <time.h> #include <stdlib.h> using namespace std; int flip(); int main () { int cara, cruz, tiraLaMoneda; for (int i=0; i < 100; i++) { tiraLaMoneda = flip(); if (tiraLaMoneda == 1) { cout<<"Salio cara"<<endl; cara++; } else { cout<<"Salio cruz"<<endl; cruz++; } } cout<<endl<<endl<<"Total cara: "<<cara<<endl <<"Total cruz: "<<cruz; system ("pause"); return 0; } int flip() { int caraCruz; int random = rand(); int parOno = random % 2; random = rand(); parOno = random % 2; if (parOno == 1) { caraCruz = 1; } else { caraCruz = 0; } return caraCruz; }
-
∞ flexible random password generator
<?php function generate_password($length, $type) { $alpha = "abcedefghijklmnopqrstuvwxyz"; $bigalpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; $numeric = "0123456789"; $symbol = "!@#$%^&*-+_"; switch ($type) { case 'alphasmall': $possible = $alpha; break; case 'alpha': $possible = $alpha . $bigalpha; break; case 'alphanumsmall': $possible = $alpha . $numeric; break; case 'alphanum': $possible = $alpha . $bigalpha . $numeric; break; case 'all': $possible = $alpha . $bigalpha . $numeric . $symbol; break; } $password = ''; for ($i=0;$i<$length;$i++) { $char = substr($possible, mt_rand(0, strlen($possible)-1), 1); $password .= $char; } return $password; } ?>
-
∞ random password generator
<?php $length = 12; //password length $password = ""; // make an empty password // define all possible characters: uppercase, lowercase, numbers, and symbols. $possible = "0123456789abcdfghjkmnpqrstvwxyzQWERTYUIOPLKJHGFDSAZXCVBNM!@#$%^&*-+_"; $i = 0; // set up counter // add random characters to $password until $length is reached while ($i < $length) { //while the password isn't yet 12 characters // pick a random character from the possible ones $char = substr($possible, mt_rand(0, strlen($possible)-1), 1); $password .= $char; // add that character to the password $i++; //increase counter } ?>
-
∞ AS2 Random From Range
function getRandom(min:Number, max:Number):Number { return Math.floor(Math.random() * (max - min + 1)) + min; }
-
∞ bash random string generation
< /dev/urandom tr -dc A-Za-z0-9 | head -c8
-
∞ Generate random password
<?php /** * Generates a random string of the specified length (default = 10). * * @return String * @author Joshua Gross **/ function generatePassword($length=10) { $randstr=''; srand((double)microtime()*1000000); $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; while(strlen($randstr)<$length) { $randstr.=substr($chars,(rand()%(strlen($chars))),1); } return $randstr; }



Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems