IMPORTANT!

Snipt is going open source. We've toyed with this idea for quite a while, and have finally decided it's the right way to move forward.

A few things:
  • The entire Snipt source code will be released on GitHub under the 3-clause BSD License on Friday, September 10th.
  • While we'd like to think we're perfect, we realize we're only human. By open sourcing the software that runs this website, certain bugs or security flaws may be discovered that could compromise the privacy of your snipts.
  • Only the Lion Burger team will be able to push commits to the Snipt.net site. Contributors should send a pull request to add new features or submit patches.
  • By using this site, you agree not to be too angry or take any legal action against Lion Burger should this whole thing go up in flames some day.
  • Follow us on Twitter for updates.
I agree, close this message
Sign up to create your own snipts, or login.

Latest 100 public snipts » random The latest public random snipts.

showing 1-20 of 24 snipts for random
  • Generate a random numeric zero-padded string
    /**
     * Function to generate a random numeric zero-padded string 
     * @param int $minChar Minimum character of the numer
     * @param int $maxChar Maximum character of the numer
     **/
    function getRandom($minChar=5, $maxChar=9){
    	$min=pow(10,$minChar-1);
    	$max=pow(10,$maxChar)-1;
    	list($usec, $sec) = explode(' ', microtime());
    	srand((float) $sec + ((float) $usec * 100000));
    	return str_pad(rand($min,$max),$maxChar,"0",STR_PAD_LEFT);
    }#end getRandom
    

    copy | embed

    0 comments - tagged in  posted by artilibere on Sep 03, 2010 at 8:08 a.m. EDT
  • Random redirect with Javascript
    <script type="text/javascript">
    var urls = new Array("http://usabilla.com/rate/A", "usabilla.com/rate/B");
    window.location = urls[Math.floor(urls.length*Math.random())];
    </script>
    

    copy | embed

    0 comments - tagged in  posted by sido on Jul 21, 2010 at 5:01 p.m. EDT
  • Real Random Sang Kaghaz Gheichi
    #include <iostream>
    #include <conio.h>
    #include <time.h>
    #include <stdio.h>
    #include <stdlib.h>
    using namespace std;
    int main()
    {
        loop:
        time_t t;
        srand((unsigned) time(&t));
        int cpu=rand();
        cpu%=3;
        cpu++;
        cout<<"\a\nSang-Kaghaz-Gheichi? (1,2,3)--0 to exit--- ";
        int user;
        cin>>user;
        if(!user) return 0;
        cout<<"\nCPU choosed "<<cpu<<".";
        if(cpu==user) cout<<"\nYou equalized!";
        else
        {
            switch(user)
            {
                        case 1:
                             if(cpu==2)
                                cout<<"\nCPU Won!";
                             else
                                cout<<"\nYou Won!";
                             break;
                        case 2:
                             if(cpu==3)
                                cout<<"\nCPU Won!";
                             else
                                cout<<"\nYou Won!";
                             break;
                        case 3:
                             if(cpu==1)
                                cout<<"\nCPU Won!";
                             else
                                cout<<"\nYou Won!";
                             break;
                        default:
                                cout<<"\nWhat was that? Please enter 1-2-3!!";
            }
        }
        getch();
        cout<<"\n\n";
        goto loop;  
    }
    

    copy | embed

    0 comments - tagged in  posted by goharshady on Jun 08, 2010 at 6:19 a.m. EDT
  • Print a random element in an Array
    #!/usr/bin/perl
    
    use strict;
    
    # Declare an Array
    my @coins = ("Quarter","Dime","Nickel");
    
    # Print a random element
    print $coins[rand @coins];
    

    copy | embed

    0 comments - tagged in  posted by alwaysonnet on Jun 06, 2010 at 12:09 p.m. EDT
  • Debugged
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    void whyCallMe(string input)
    {
        if (input == "urgent")
            cout << "because it is urgent lar" << endl;
        else if (input == "miss you")
            cout << "you wait long long"<<endl;
    
        else
            cout << "Not answering your calls";
    }
    void plsDunCallMe()
    {
    
        string a = "there is more then one way to skin the cat";
        cout << a << endl;
    }
    int func1(int x, int y)
    {
        int result = 0;
        result = x + y;
        return result;
    }
    
    int main()
    {
    
        int result = 0,x=10,y=20;
        string strIn = "";
        cout << "Spot the common mistake(s)" << endl;
        result = func1(x,y);
        cout << "sum 10+20: " << result << endl;
        plsDunCallMe();
    
        while (1)
        {
            cout << "Why You Called?";
    
            getline(cin,strIn);
            whyCallMe(strIn);
            cout << endl;
    
            if (strIn == "urgent");
    
        }
        return 0;
    }
    

    copy | embed

    0 comments - tagged in  posted by hAkomen on Apr 26, 2010 at 10:44 a.m. EDT
  • Very interesting way to generate a random string. Doesn't work on Snow Leopard tho.
    </dev/urandom tr -dc A-Za-z0-9./%? | head -c 10
    

    copy | embed

    0 comments - tagged in  posted by mandric on Apr 16, 2010 at 10:23 a.m. EDT
  • randRange - random number within a given range
    private function randRange(start:Number, end:Number):Number{
        return Math.floor(start +(Math.random() * (end - start)));
    }
    

    copy | embed

    0 comments - tagged in  posted by bromanji on Apr 07, 2010 at 12:51 p.m. EDT
  • random md5
    md5(uniqid(rand(), true));
    

    copy | embed

    0 comments - tagged in  posted by nicolascormier on Feb 08, 2010 at 7:49 p.m. EST
  • 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";
        }
      } 
    }
    

    copy | embed

    0 comments - tagged in  posted by rschu68 on Jan 05, 2010 at 8:58 a.m. EST
  • 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))];
    	}
    }
    ?>
    

    copy | embed

    0 comments - tagged in  posted by kor on Dec 02, 2009 at 7:34 p.m. EST
  • 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;
    }
    

    copy | embed

    0 comments - tagged in  posted by Rajendran on Nov 27, 2009 at 1:32 a.m. EST
  • random number as3
    var ran:int = Math.round(Math.random() * (high - low)) + low;
    

    copy | embed

    0 comments - tagged in  posted by corbanb on Sep 08, 2009 at 5:33 p.m. EDT
  • 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
    

    copy | embed

    0 comments - tagged in  posted by sistematico on Aug 15, 2009 at 5:33 p.m. EDT
  • javascript random string function
    function rnd(){ return String((new Date()).getTime()).replace(/\D/gi,'') }
    

    copy | embed

    0 comments - tagged in  posted by joeydi on Aug 12, 2009 at 12:34 a.m. EDT
  • 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;
    ?>
    

    copy | embed

    0 comments - tagged in  posted by datagutt on Aug 01, 2009 at 2:25 p.m. EDT
  • Simple generation of random string in Python
    import string
    import random
    
    print "".join(random.sample(string.letters+string.digits, 8))
    

    copy | embed

    0 comments - tagged in  posted by Fotinakis on Jun 18, 2009 at 1:14 p.m. EDT
  • 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>"; }	?>
    

    copy | embed

    0 comments - tagged in  posted by NightFalcon on Mar 29, 2009 at 9:09 p.m. EDT
  • Lua random thing
    str = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890"
    for i = 0,#str do
    i = i + 1
    io.write(string.sub(str,i,i))
    end
    

    copy | embed

    0 comments - tagged in  posted by WhileTrueDo on Mar 19, 2009 at 12:13 p.m. EDT
  • 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;
    }
    

    copy | embed

    2 comments - tagged in  posted by YamilG on Mar 16, 2009 at 10:42 p.m. EDT
  • 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;
    }
    
    ?>
    

    copy | embed

    0 comments - tagged in  posted by ruxid on Mar 15, 2009 at 6:46 a.m. EDT
Sign up to create your own snipts, or login.