Android (int) (Math.random() * 100 % 4) 的结果

博主前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住也分享一下给大家,
👉点击跳转到网站

Math类是数学类,调用random()方法生成0~1(0<=x<1)的随机数,乘于100 生成0~100(不包括100)的随机数
% 这个表示取模运算或者求余运算
0~100的数 取模运算之后 为0~4的随机数(取不到4,只是无限接近于4)

(int) (Math.random() * 100 % 4) :表示强制取整,把小数点去掉只剩整数部分。

综上分析:(int) (Math.random() * 100 % 4) 的结果为:0~3之间的随机整数

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
public class ConstellationDetailActivity extends BaseBindingActivity<ActivityConstellationDetailBinding> { private Random random = new Random(); private BindAdapter<ItemDetailBinding, Pair<String, String>> adapter = new BindAdapter<ItemDetailBinding, Pair<String, String>>() { @Override public ItemDetailBinding createHolder(ViewGroup parent) { return ItemDetailBinding.inflate(getLayoutInflater(), parent, false); } @Override public void bind(ItemDetailBinding itemDetailBinding, Pair<String, String> kv, int position) { itemDetailBinding.tvName.setText(kv.first); itemDetailBinding.tvValue.setText(kv.second); itemDetailBinding.tvValue.setBackgroundColor(Color.rgb(43 + (int) (Math.random() * (206 - 43 + 1)), 43 + (int) (Math.random() * (206 - 43 + 1)), 43 + (int) (Math.random() * (206 - 43 + 1)))); } }; @Override protected void initListener() { } @Override protected void initData() { Constellation constellation = (Constellation) getIntent().getSerializableExtra("constellation"); adapter.getData().add(Pair.create("特点", constellation.features)); adapter.getData().add(Pair.create("颜色", constellation.color)); adapter.getData().add(Pair.create("主管星", constellation.supervisorStar)); adapter.getData().add(Pair.create("幸运号码", constellation.luckyNumber)); adapter.getData().add(Pair.create("掌管宫位", constellation.palace)); adapter.getData().add(Pair.create("金属", constellation.metal)); viewBinder.rvDetail.setAdapter(adapter); Glide.with(this).load(App.starImageMap.get(constellation.name)).into(viewBinder.ivImage); viewBinder.tvName.setText(constellation.name); viewBinder.tvTime.setText(constellation.timeOfBirth); viewBinder.tvDetail.setText(constellation.analysis); } }什么意思
最新发布
05-18

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

路宇

你的鼓励将是我创作的最大动力

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

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

打赏作者

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

抵扣说明:

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

余额充值