相关疑难解决方法(0)

java的UUID.randomUUID有多好?

我知道随机UUID在理论上具有非常非常非常低的碰撞概率,但我想知道,在实践中,Java 5 randomUUID()在没有碰撞方面有多好?有没有人有经验可以分享?

java uuid

300
推荐指数
8
解决办法
16万
查看次数

在android(UUID)中生成唯一ID

几个月来,我一直在使用一个类来生成一个在reintalls之间稳固的UUID.我的应用程序是关于折扣,所以我依靠这个UUID来限制每台设备的优惠券数量.

protected void getDeviceId(){
    try {
        Context context = cordova.getActivity().getApplicationContext();
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

        String uuid;
        String androidID = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
        String deviceID = tm.getDeviceId();
        String simID = tm.getSimSerialNumber();

        if ("9774d56d682e549c".equals(androidID) || androidID == null) {
            androidID = "";
        }

        if (deviceID == null) {
            deviceID = "";
        }

        if (simID == null) {
            simID = "";
        }

        uuid = androidID + deviceID + simID;
        uuid = String.format("%32s", uuid).replace(' ', '0');
        uuid = uuid.substring(0, 32);
        uuid = uuid.replaceAll("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})", "$1-$2-$3-$4-$5"); …
Run Code Online (Sandbox Code Playgroud)

android

5
推荐指数
2
解决办法
2万
查看次数

标签 统计

android ×1

java ×1

uuid ×1