[震惊]PHP用整数生成绝对不重复的唯一ID类库——Hashids》》》》》》》出现了重复!!!!咋回事?

需求生成一个6位数的自增不重复的短链接,于是
在网上看到《PHP用整数生成绝对不重复的唯一ID类库——Hashids》,试了一下,无论怎么改salt,每次执行到200条左右就出现重复值,这是咋回事

composer require vinkla/hashids
  • 迁移文件
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateHashidsTestsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('hashids_tests', function (Blueprint $table) {
            $table->id();
            $table->string('hashids')->unique('hashids')->default(0);
            $table->integer('ids_text')->default(0);
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('hashids_tests');
    }
}
  • 执行
    set_time_limit(0);
   for ($i = 1;$i<1000000;$i++){
       $hashids = Hashids::encode($i);
        HashidsTest::query()->create([
            'hashids' => $hashids,
            'ids_text' => $i,
        ]);
   }

PHP用整数生成绝对不重复的唯一ID类库——Hashids》》》》》》》出现了重复!!!!咋回事?

《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
最佳答案

大小写问题,你可以全部大写或者全部小写

2年前 评论
Ranger9527 2年前
my38778570 (楼主) 2年前
讨论数量: 5

大小写问题,你可以全部大写或者全部小写

2年前 评论
Ranger9527 2年前
my38778570 (楼主) 2年前

用 _bin 类的字符 collation,大小写敏感

2年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!