如何随机化?

扫码查看
本文介绍了如何随机化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始学习Java,我们有一个需要展示洗牌的项目。我们正在使用物体作为我们的扑克牌,我们已将这些物品放在堆叠中,我想知道是否有人可以帮助我如何洗牌。这些对象或以随机排列放置?

解决方案




好​​的,非常感谢。我会尝试并尽快发布我想出的内容,因为到目前为止我仍然没有想出如何制作这些物品(卡片)。




我已经想出如何使用Math.random()包,但有没有办法让生成的数字唯一?例如,我只需要0到51之间的数字。你能告诉我如何只生成一个随机数一次,这样最终看起来我是按照随机顺序重新排列数字0到51吗?

I''m just starting learning Java, and we have a project that needs to demonstrate shuffling playing cards. We''re using objects as our playing cards, and we''ve put these objects in stacks, and I wonder if anyone can help me how to "shuffle" these objects or put them in a random arrangement?

解决方案


Okay, thanks very much. I''ll try it and post what I come up with as soon as I can, because as of yet I still haven''t figured out how to make the objects (cards).


I''ve figured out how to use Math.random() package, but is there a way to make the generated numbers unique? For example, I only need numbers from 0 to 51. Can you tell me how I generate one random number only once so that in the end, it seems like I''m rearranging the numbers 0 to 51 in a random sequence?


这篇关于如何随机化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 17:36
查看更多