示例#1
0
<?php

class RandomString
{
    public static function generate($length)
    {
        $string = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, $length);
        return $string;
    }
}
echo RandomString::generate(32);
示例#2
0
$form->addElement('text', 'lines', 'Number of strings:', array('size' => 2, 'maxlength' => 2));
$form->addElement('checkbox', 'useLower', 'Use lower case (a-z):');
$form->addElement('checkbox', 'useUpper', 'Use upper case (A-Z):');
$form->addElement('checkbox', 'useNumbers', 'Use integers(0-9):');
$form->addElement('checkbox', 'useChars', 'Use symbols (!$%^...):');
$form->addElement('submit', null, 'Generate!');
// Rules
$form->addRule('length', 'Length is required', 'required', '', 'client');
$form->addRule('lines', 'Number of strings required', 'required', '', 'client');
// Output
echo "<html><body><center>\n";
$form->display();
// Try to validate, and generate strings if valid
if ($form->validate()) {
    try {
        $r = new RandomString();
        $r->setOption('useChars', (bool) $form->exportValue('useChars'));
        $r->setOption('useLower', (bool) $form->exportValue('useLower'));
        $r->setOption('useUpper', (bool) $form->exportValue('useUpper'));
        $r->setOption('useNumbers', (bool) $form->exportValue('useNumbers'));
        $r->setOption('lines', $form->exportValue('lines'));
        $r->setOption('length', $form->exportValue('length'));
        foreach ($r->getStrings() as $string) {
            echo "<h2>{$string}</h2>";
        }
    } catch (Exception $e) {
        echo "<h2>Error: " . $e->getMessage() . "</h2>\n";
    }
}
echo "<a href='http://github.com/shupp/RandomString'>Code</a>\n";
echo "</center></body></html>";
示例#3
0
文件: all.php 项目: ebbz/firefly-iii
    return $email;
}, 'password' => bcrypt('james')]);
FactoryMuffin::define('FireflyIII\\Models\\Transaction', ['transaction_journal_id' => 'factory|FireflyIII\\Models\\TransactionJournal', 'amount' => function () {
    return rand(1, 100);
}, 'description' => 'sentence', 'account_id' => 'factory|FireflyIII\\Models\\Account']);
FactoryMuffin::define('FireflyIII\\Models\\PiggyBank', ['account_id' => 'factory|FireflyIII\\Models\\Account', 'name' => 'sentence', 'targetamount' => function () {
    return rand(1, 100);
}, 'startdate' => 'date', 'targetdate' => 'date', 'remind_me' => false, 'reminder_skip' => 0, 'order' => 0]);
FactoryMuffin::define('FireflyIII\\Models\\PiggyBankRepetition', ['piggy_bank_id' => 'factory|FireflyIII\\Models\\PiggyBank', 'startdate' => 'date', 'targetdate' => 'date', 'currentamount' => function () {
    return rand(1, 100);
}]);
FactoryMuffin::define('FireflyIII\\Models\\PiggyBankEvent', ['piggy_bank_id' => 'factory|FireflyIII\\Models\\PiggyBank', 'transaction_journal_id' => 'factory|FireflyIII\\Models\\TransactionJournal', 'date' => 'date', 'amount' => function () {
    return rand(1, 100);
}]);
FactoryMuffin::define('FireflyIII\\Models\\TransactionType', ['type' => function () {
    $types = ['Withdrawal', 'Deposit', 'Transfer'];
    $count = DB::table('transaction_types')->count();
    if ($count < 3) {
        return $types[$count];
    } else {
        return RandomString::generateRandomString(10);
    }
}]);
FactoryMuffin::define('FireflyIII\\Models\\TransactionJournal', ['user_id' => 'factory|FireflyIII\\User', 'transaction_type_id' => 'factory|FireflyIII\\Models\\TransactionType', 'transaction_currency_id' => 'factory|FireflyIII\\Models\\TransactionCurrency', 'description' => 'sentence', 'completed' => '1', 'date' => 'date', 'encrypted' => '1', 'order' => '0'], function (TransactionJournal $object, $saved) {
    if ($saved) {
        $one = FactoryMuffin::create('FireflyIII\\Models\\Account');
        $two = FactoryMuffin::create('FireflyIII\\Models\\Account');
        Transaction::create(['account_id' => $one->id, 'transaction_journal_id' => $object->id, 'amount' => 100]);
        Transaction::create(['account_id' => $two->id, 'transaction_journal_id' => $object->id, 'amount' => -100]);
    }
});
 public function __construct()
 {
     parent::__construct(explode(',', 'Morning,Afternoon,Evening,Night'));
 }