PHP code example of jesus-ag28 / php-random
1. Go to this page and download the library: Download jesus-ag28/php-random library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jesus-ag28 / php-random example snippets
use Random\Random;
// Generar un número entero aleatorio
$numero = Random::int(1, 100);
// Generar una cadena aleatoria
$cadena = Random::string(20);
// Generar un booleano aleatorio
$bool = Random::boolean();
Random::int(1, 100); // Número entre 1 y 100
Random::int(); // Número entre 0 y PHP_INT_MAX
Random::float(0, 1); // Float entre 0 y 1
Random::float(10.5, 20.5); // Float entre 10.5 y 20.5
Random::string(15); // "aBc123!@ñÑ"
Random::password(16); // "aB3!xY9@mN5#qW2$"
Random::password(12, false); // "aBc123XyZ789"
Random::verificationCode(6); // "aB3xY9"
Random::verificationCode(6, true); // "123456"
Random::slug(3); // "random-test-example-456"
Random::token(32); // "a1b2c3d4e5f6..."
Random::base64Token(32); // "YWJjZGVm..."
Random::uuid(); // "550e8400-e29b-41d4-a716-446655440000"
Random::boolean(); // true o false
Random::array(5); // [123, 456, 789, 101, 112]
Random::array(3, fn() => Random::string(5)); // ["aBc12", "xYz34", "mNp56"]
Random::fromArray(['rojo', 'verde', 'azul']); // "verde"
Random::weightedPick(['común', 'raro', 'épico'], [70, 25, 5]); // "común" (70% probabilidad)
Random::shuffle([1, 2, 3, 4, 5]); // [3, 1, 5, 2, 4]
enum Color { case Red; case Green; case Blue; }
Random::enum(Color::class); // Color::Green
Random::date('2020-01-01', '2024-12-31'); // "2022-06-15"
Random::dateTime('2023-01-01 00:00:00', '2023-12-31 23:59:59'); // "2023-06-15 14:30:45"
Random::color(); // "#a1b2c3"
Random::hexColor(); // "a1b2c3"
Random::latitude(); // 45.123456
Random::longitude(); // -73.987654
Random::coordinates(); // ['latitude' => 45.123456, 'longitude' => -73.987654]
Random::email(); // "[email protected] "
Random::email('midominio.com'); // "[email protected] "
Random::ipAddress(); // "192.168.1.100"
Random::macAddress(); // "a1:b2:c3:d4:e5:f6"
Random::domainName(8); // "abcdefgh.com"
Random::url(15); // "https://www.example.com/abc123xyz"
Random::userAgent(); // "Mozilla/5.0 (Windows NT 10.0; Win64; x64)..."
Random::fullName(); // "Juan García López"
Random::fullName(false); // "John Smith Johnson"
Random::postalAddress(); // "Calle Mayor, 28001, Madrid, Madrid"
Random::postalAddress(false); // "Main St, 10001, New York, NY"
Random::phoneNumber(); // "65 123 45 67"
Random::phoneNumber(false); // "555-123-4567"
Random::internationalPhoneNumber(); // "+34 65 123 45 67"
Random::internationalPhoneNumber(false); // "+1-555-123-4567"
// Totalmente aleatorio
Random::username(); // "DragonWarrior"
Random::username(2, 1); // "ThunderPhoenixMaster"
Random::username(1, 2); // "CyberNinjaHunter"
Random::username(3, 0); // "DragonTitanStorm"
Random::username(0, 3); // "MightySwiftDark"
// Con palabra personalizada
Random::username('Jesus', 1); // "JesusWarrior"
Random::username('Maria', 2); // "MariaSwiftDark"
// Con adjetivo personalizado
Random::username(1, 'Pro'); // "DragonPro"
Random::username(2, 'Gaming'); // "ThunderPhoenixGaming"
// Ambos personalizados con aleatorios
Random::username('Dark', 1); // "DarkHunter"
Random::username(1, 'Legend'); // "PhoenixLegend"
// Solo personalizados
Random::username('Shadow', 'Master'); // "ShadowMaster"
Random::username('Cyber', 'King'); // "CyberKing"
// Mezcla compleja
Random::username('Epic', 2); // "EpicMightySwift"
Random::username(2, 'Ultimate'); // "DragonPhoenixUltimate"
Random::creditCardNumber(); // "4532123456789012"
Random::fileSize(); // "15.6 MB"
Random::fileSize(1024, 1048576); // "512.3 KB"
use Random\Random;
$usuario = [
'nombre' => Random::fullName(),
'email' => Random::email('miapp.com'),
'telefono' => Random::phoneNumber(),
'direccion' => Random::postalAddress(),
'username' => Random::username(),
'password' => Random::password(16),
'uuid' => Random::uuid(),
'fecha_registro' => Random::dateTime('2023-01-01 00:00:00'),
];
$token = Random::token(64);
$apiKey = Random::base64Token(32);
$codigoSMS = Random::verificationCode(6, true); // Solo números
$codigoEmail = Random::verificationCode(8); // Alfanumérico
$coordenadas = Random::coordinates();
echo "Lat: {$coordenadas['latitude']}, Lon: {$coordenadas['longitude']}";
bash
composer