通过随机数生成流程实例号

该代码段展示了如何使用SNNoTools类生成一个介于0和9999999999之间的随机整数,用于设置workflowInstance的唯一标识。方法通过两个0到10之间的随机数相乘得到结果,确保生成的编号不超过预设的最大值。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

结论:最大取数 不超过 999999999 9位


        workflowInstance.setWorkflowInstanceId("WFI" + SNNoTools.getIntUUID().toString());

WFI101687200
在这里插入图片描述

package com.tn.mdm.workflow.tools;

/**
 * 生成编号
 *
 * @author admin
 * @date 2022-04-25
 */
public class SNNoTools {

    public static synchronized Integer getIntUUID() {
        Integer data = 0;
        while (data <= 0) {
            Integer numOne = Math.abs((int) Math.round((Math.random() * 10) * 10000000));   // [0,1)x10=个位数,个位数x7个0  <= 8位
            Integer numTwo = Math.abs((int) Math.round((Math.random() * 10)));              // [0,1)x10=个位数,个位数x最大8位  <= 9位
            data = numOne * numTwo;
        }
        return data;
    }


    public static void main(String[] args) {
        Integer data = 0;
        Integer numOne = Math.abs((int) Math.round((Math.random() * 10) * 10000000));
        Integer numTwo = Math.abs((int) Math.round((Math.random() * 10)));
        data = numOne * numTwo;
    }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

码元宋大米

感谢小主大赏,留言可进互助群~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值