【问题标题】:how to generate a random base64 number to power of 11如何生成随机 base64 数的 11 次幂
【发布时间】:2017-10-18 15:23:38
【问题描述】:

我正在尝试处理 url,所以我需要一个随机 base64 的 11 次幂,每次刷新页面时都会改变。

我在 php 中工作。 任何帮助都会很棒, 非常感谢。

不知道该怎么做,但可能会像下面这样?

function toChars($number) {
$res = base_convert($number, 10,26);
$res = strtr($res,'0123456789','qrstuvxwyz');
return $res;
}

$res = ('0123456789','abcdefghijklmnopqrstuvxwyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ');

然后从中随机选择,直到你得到一个 11 位数字,也就是(base64 到 11 的幂)

并在此处回显数字 $random_base64_number = ?

【问题讨论】:

  • 你试过什么?你被困在哪里了?什么是你想要达到的确切结果的一个很好的例子? idownvotedbecau.se/noattempt
  • 不知道该怎么做。但也许是这样的?函数 toChars($number) { $res = base_convert($number, 10,26); $res = strtr($res,'0123456789','qrstuvxwyz');返回 $res; }
  • 请“编辑”您的问题以添加更多内容。您的标签下有一个小的编辑链接。

标签: php random numbers base64


【解决方案1】:

别着急想通了。

function base62() {
 $index = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_';
$res = '';
for ($x = 1; $x <= 11; $x++) {
$res .= $index[rand(1, strlen($index))];
}
echo "The number is: $res <br>";
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-04
    • 2013-11-09
    • 1970-01-01
    • 2022-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多