Heim > Backend-Entwicklung > PHP-Tutorial > 请教生成字母加数字

请教生成字母加数字

WBOY
Freigeben: 2016-06-23 13:27:17
Original
1119 Leute haben es durchsucht

有26个字母{a-Z}和10个数字{0-9}
如果要生成8位字符的,区分大小写,
这样的排列是(26+26+10)8次方=218340105584896个,这218万亿
但相邻不能有两个或以上相同的如{a1b2cc90,这个字符出现了两次cc}
这样的数据可以用PHP来产生吗?
如果生成单个文本数据应该不太可能,得切割成好多份……


回复讨论(解决方案)

这个意思?

$d = str_split('abcd');print_r(array_map('join', f(4, $d)));function f($n, $d) {  $t = array_chunk($d, 1);  if($n > 2) $t = f($n-1, $d);  foreach($t as $x)    foreach(array_chunk($d, 1) as $y) {      if(end($x) != end($y)) $r[] = array_merge($x, $y);    }  return $r;}
Nach dem Login kopieren
Array(    [0] => abab    [1] => abac    [2] => abad    [3] => abca    [4] => abcb    [5] => abcd    [6] => abda    [7] => abdb    [8] => abdc    [9] => acab    [10] => acac    [11] => acad    [12] => acba    [13] => acbc    [14] => acbd    [15] => acda    [16] => acdb    [17] => acdc    [18] => adab    [19] => adac    [20] => adad    [21] => adba    [22] => adbc    [23] => adbd    [24] => adca    [25] => adcb    [26] => adcd    [27] => baba    [28] => babc    [29] => babd    [30] => baca    [31] => bacb    [32] => bacd    [33] => bada    [34] => badb    [35] => badc    [36] => bcab    [37] => bcac    [38] => bcad    [39] => bcba    [40] => bcbc    [41] => bcbd    [42] => bcda    [43] => bcdb    [44] => bcdc    [45] => bdab    [46] => bdac    [47] => bdad    [48] => bdba    [49] => bdbc    [50] => bdbd    [51] => bdca    [52] => bdcb    [53] => bdcd    [54] => caba    [55] => cabc    [56] => cabd    [57] => caca    [58] => cacb    [59] => cacd    [60] => cada    [61] => cadb    [62] => cadc    [63] => cbab    [64] => cbac    [65] => cbad    [66] => cbca    [67] => cbcb    [68] => cbcd    [69] => cbda    [70] => cbdb    [71] => cbdc    [72] => cdab    [73] => cdac    [74] => cdad    [75] => cdba    [76] => cdbc    [77] => cdbd    [78] => cdca    [79] => cdcb    [80] => cdcd    [81] => daba    [82] => dabc    [83] => dabd    [84] => daca    [85] => dacb    [86] => dacd    [87] => dada    [88] => dadb    [89] => dadc    [90] => dbab    [91] => dbac    [92] => dbad    [93] => dbca    [94] => dbcb    [95] => dbcd    [96] => dbda    [97] => dbdb    [98] => dbdc    [99] => dcab    [100] => dcac    [101] => dcad    [102] => dcba    [103] => dcbc    [104] => dcbd    [105] => dcda    [106] => dcdb    [107] => dcdc)
Nach dem Login kopieren

Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage