扑克牌洗牌
代码比较简单。
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace RandomNumber { public class RandomCreater { // 随机数生成器只需要一个 private static readonly System.Random random = new Random(); public int [] Random( int [] array) { int length = array.Length; for ( int i = 0; i < length - 1; i++) { // 随机生成准备交换的下标 int index = random.Next(i + 1, length); // 与当前的数字进行交换 int t = array[i]; array[i] = array[index]; array[index] = t; } return array; } } class Program { static void Main( string [] args) { // 首先创建一个有序的数组 int [] array = new int [54]; for ( int i = 0; i < 54; i++) array[i] = i + 1; // 进行随机处理 RandomCreater rc = new RandomCreater(); int [] randomArray = rc.Random(array); // 输出 for ( int i = 0; i < randomArray.Length; i++) Console.Write( "{0} " , randomArray[i]); Console.WriteLine(); } } } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?