相关疑难解决方法(0)

使用Random和OrderBy是一个很好的shuffle算法吗?

我在Coding Horror上读过一篇关于各种shuffle算法的文章.我已经看到人们已经在某个地方对列表进行了洗牌:

var r = new Random();
var shuffled = ordered.OrderBy(x => r.Next());
Run Code Online (Sandbox Code Playgroud)

这是一个很好的shuffle算法吗?它是如何工作的?这样做是否可以接受?

c# algorithm shuffle

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

使用.NET随机化数组的最佳方法

使用.NET随机化字符串数组的最佳方法是什么?我的数组包含大约500个字符串,我想Array用随机顺序创建一个具有相同字符串的新字符串.

请在答案中加入C#示例.

.net c# sorting random algorithm

128
推荐指数
4
解决办法
13万
查看次数

这个改组算法有什么问题吗?

我一直在做一些休闲度假计算.我的迷你项目是对意大利"tomboli"游戏的模拟.一个关键的构建模块是对以下过程的模拟;

游戏由一个男人控制,一袋90个大理石,编号为1到90.他从包里随机抽出弹珠,每次都给玩家打出大理石号码.

经过一番思考后,我为这个构建块编写了以下代码;

// NBR marbles, numbered 1...NBR are in a bag. Simulate randomly
//  pulling them from the bag, one by one, until the bag is empty
void bag( int random_sequence[NBR] )
{
    int i;

    // Store each marble as it is pulled out
    int *store = random_sequence;

    // Array of marbles still in the bag
    int not_yet_pulled[NBR];
    for( i=0; i<NBR; i++ )
        not_yet_pulled[i] = i+1;    // eg NBR=90; 1,2,3 ... 90

    // Loop pulling marbles from the bag, …
Run Code Online (Sandbox Code Playgroud)

c c++ random algorithm simulation

4
推荐指数
3
解决办法
1783
查看次数

标签 统计

algorithm ×3

c# ×2

random ×2

.net ×1

c ×1

c++ ×1

shuffle ×1

simulation ×1

sorting ×1