Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Answer

Active reading [<https://en.wikipedia.org/wiki/PHP#PHP_7>].
Source Link
Peter Mortensen
  • 31.3k
  • 22
  • 110
  • 134

A better way to implement this function is:

function RandomString($length) {
 $keys = array_merge(range(0,9), range('a', 'z'));
 $key = "";
 for($i=0; $i < $length; $i++) {
 $key .= $keys[mt_rand(0, count($keys) - 1)];
 }
 return $key;
}
echo RandomString(20);

mt_rand is more random according to this and this in php7PHP 7. The rand function is an alias of mt_rand.

A better way to implement this function is:

function RandomString($length) {
 $keys = array_merge(range(0,9), range('a', 'z'));
 $key = "";
 for($i=0; $i < $length; $i++) {
 $key .= $keys[mt_rand(0, count($keys) - 1)];
 }
 return $key;
}
echo RandomString(20);

mt_rand is more random according to this and this in php7. rand function is an alias of mt_rand.

A better way to implement this function is:

function RandomString($length) {
 $keys = array_merge(range(0,9), range('a', 'z'));
 $key = "";
 for($i=0; $i < $length; $i++) {
 $key .= $keys[mt_rand(0, count($keys) - 1)];
 }
 return $key;
}
echo RandomString(20);

mt_rand is more random according to this and this in PHP 7. The rand function is an alias of mt_rand.

short php7 clearness
Source Link
SUB0DH
  • 5.3k
  • 5
  • 32
  • 47

A better way to implement this function is:

function RandomString($length) {
 $keys = array_merge(range(0,9), range('a', 'z'));
 $key = "";
 for($i=0; $i < $length; $i++) {
 $key .= $keys[mt_rand(0, count($keys) - 1)];
 }
 return $key;
}
echo RandomString(20);

mt_rand is more random according to this and this in php7. rand function is an alias of mt_rand.

A better way to implement this function is:

function RandomString($length) {
 $keys = array_merge(range(0,9), range('a', 'z'));
 $key = "";
 for($i=0; $i < $length; $i++) {
 $key .= $keys[mt_rand(0, count($keys) - 1)];
 }
 return $key;
}
echo RandomString(20);

mt_rand is more random according to this and this in php7 rand function is an alias of mt_rand.

A better way to implement this function is:

function RandomString($length) {
 $keys = array_merge(range(0,9), range('a', 'z'));
 $key = "";
 for($i=0; $i < $length; $i++) {
 $key .= $keys[mt_rand(0, count($keys) - 1)];
 }
 return $key;
}
echo RandomString(20);

mt_rand is more random according to this and this in php7. rand function is an alias of mt_rand.

A better way to implement this function is:

function RandomString($length) {
 $keys = array_merge(range(0,9), range('a', 'z'));
 $key = "";
 for($i=0; $i < $length; $i++) {
 $key .= $keys[mt_rand(0, count($keys) - 1)];
 }
 return $key;
}
echo RandomString(20);

mt_rand is more random according to this and this in php7 rand function is an alias of mt_rand.

A better way to implement this function is:

function RandomString($length) {
 $keys = array_merge(range(0,9), range('a', 'z'));
 $key = "";
 for($i=0; $i < $length; $i++) {
 $key .= $keys[mt_rand(0, count($keys) - 1)];
 }
 return $key;
}
echo RandomString(20);

mt_rand is more random according to this and this

A better way to implement this function is:

function RandomString($length) {
 $keys = array_merge(range(0,9), range('a', 'z'));
 $key = "";
 for($i=0; $i < $length; $i++) {
 $key .= $keys[mt_rand(0, count($keys) - 1)];
 }
 return $key;
}
echo RandomString(20);

mt_rand is more random according to this and this in php7 rand function is an alias of mt_rand.

Loading
improved randomness of the output
Source Link
azerafati
  • 18.7k
  • 7
  • 73
  • 77
Loading
Copy edited.
Source Link
Peter Mortensen
  • 31.3k
  • 22
  • 110
  • 134
Loading
Source Link
Loading
lang-php

AltStyle によって変換されたページ (->オリジナル) /