生成很少唯一值的数据集 [英] Generating a dataset with few unique values

查看:126
本文介绍了生成很少唯一值的数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注:这是一个2部分的问题部分2

Note: This is part 2 of a 2 part question.

<一个href="http://stackoverflow.com/questions/7047896/algorithm-for-generating-a-nearly-sorted-list-on-$p$pdefined-data"标题=第1部分>第1部分这里

我想更多的排序算法什么更好的方式做比再code!所以,我想我需要一些数据的工作。

I'm wanting to more about sorting algorithms and what better way to do than then to code! So I figure I need some data to work with.

我的方法来创建一些标准的数据如下:创建项目的定数,不知道如何大做,但我想有乐趣,让我的电脑捞到一点点:D

My approach to creating some "standard" data will be as follows: create a set number of items, not sure how large to make it but I want to have fun and make my computer groan a little bit :D

在我有一个名单,我将它推到一个文本文件中,只是读出,要对运行我的算法。我应该有一个总的填充相同的数据4个文本文件,但只是排序不同运行我的算法对(见下文)。

Once I have that list, I'll push it into a text file and just read off that to run my algorithms against. I should have a total of 4 text files filled with the same data but just sorted differently to run my algorithms against (see below).

纠正我,如果我错了,但我相信,我需要4种不同的场景来分析我的算法。

Correct me if I'm wrong but I believe I need 4 different types of scenarios to profile my algorithms.

  • 在随机排序的数据(这个我会用克努特洗牌)
  • 在反向数据(很容易)
  • 在近排序(不知道如何实现这一点)
  • 在一些独特的(再一次不知道如何处理这一点)

这个问题是生成列表数据的一些独特的物品。

This question is for generating a list with a few unique items of data.

哪种方法是最好的产生具有一些独特的项目的数据集。

Which approach is best to generate a dataset with a few unique items.

推荐答案

在这里回答我的问题。不知道这是不是最好的,但它的工作原理。

Answering my own question here. Don't know if this is the best but it works.

    public static int[] FewUnique(int uniqueCount, int returnSize)
    {
        Random r = _random;
        int[] values = new int[uniqueCount];
        for (int i = 0; i < uniqueCount; i++)
        {
            values[i] = i;
        }

        int[] array = new int[returnSize];
        for (int i = 0; i < returnSize; i++)
        {
            array[i] = values[r.Next(0, values.Count())];
        }

        return array;
    }

这篇关于生成很少唯一值的数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆