Rand php

Ejemplos de código

20
0

Generador de cadenas aleatorias PHP

function generateRandomString($length = 25) {
    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $charactersLength = strlen($characters);
    $randomString = '';
    for ($i = 0; $i < $length; $i++) {
        $randomString .= $characters[rand(0, $charactersLength - 1)];
    }
    return $randomString;
}
//usage 
$myRandomString = generateRandomString(5);
8
0

generador de números aleatorios en php

you can use rand() function for that in php.
Example:
Generate random numbers between 1 to 50
<?php
  echo rand(1,50);
?>
7
0

php número aleatorio

// $min and $max are optional
rand($min,$max);
6
0

cadena aleatoria de php

function rand_str() {
    $characters = '0123456789-=+{}[]:;@#~.?/&gt;,&lt;|\!"£$%^&amp;*()abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $randomstr = '';
    for ($i = 0; $i < random_int(50, 100); $i++) {
      $randomstr .= $characters[rand(0, strlen($characters) - 1)];
    }
    return $randomstr;
  }
4
0

generador de números aleatorios php

<?php
  echo rand(1,50);
?>
2
0

php rand int

random_int ( int $min , int $max );
2
0

entero aleatorio de php

echo random_int(0,50);
0
0

php rand vs mt_rand

// Since PHP7.1 rand() has become an alias of mt_rand()
// mt_rand() was supposed to be faster and more random than rand() in older PHP Versions
// That means you can use rand() instead of mt_rand() on newer Versions
<?php
  rand(1, 100);		// will generate a random number between 1 and 100
?>

En otros idiomas

Esta página está en otros idiomas

Русский
..................................................................................................................
English
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................