Generator.OnGenerateNextValues 方法

根据数据生成算法生成下一个值。

命名空间:  Microsoft.Data.Schema.Tools.DataGenerator
程序集:  Microsoft.Data.Schema.Tools(在 Microsoft.Data.Schema.Tools.dll 中)

语法

声明
Protected Overridable Sub OnGenerateNextValues
protected virtual void OnGenerateNextValues()
protected:
virtual void OnGenerateNextValues()
abstract OnGenerateNextValues : unit -> unit 
override OnGenerateNextValues : unit -> unit 
protected function OnGenerateNextValues()

备注

OnGenerateNextValues 方法在数据生成计划运行时创建数据。 您必须重写此方法才能为数据生成器的输出属性提供生成数据的逻辑。

GenerateNextValues 方法调用此方法。 若要修改 GenerateNextValues 的功能,则必须重写 OnGenerateNextValues。

示例

此示例重写 OnGenerateNextValues 方法,以便为数据生成器生成随机数据。 此代码示例摘自一个为 Generator 类提供的更大示例。

DateTime mRandomDate;
Random mRandom;
Random mRandomRange;

protected override void OnGenerateNextValues()
{
    DateTime min;
    DateTime max;

    // Generate a random date from either range 1 or range 2.
    // Randomly select either range 1 or range 2 by randomly 
    // generating an odd or an even random number.
    if (mRandomRange.Next() % 2 == 0)  //check for odd or even
    {
        min = mRange1Min;
        max = mRange1Max;
    }
    else
    {
        min = mRange2Min;
        max = mRange2Max;
    }

    // The formula for creating a random number in a specific range is:
    // start of range + (size of range * random number between 0 and 1)

    // Size of range
    TimeSpan range = max - min;

    // (Size of range * random number between 0 and 1)
    TimeSpan randomNumber = new TimeSpan((long)(range.Ticks * mRandom.NextDouble()));

    // Start of range + (size of range * random number between 0 and 1)
    mRandomDate = min + randomNumber;
}
Dim mRandomDate As Date
Dim mRandom As Random
Dim mRandomRange As Random 

Protected Overrides Sub OnGenerateNextValues()
    Dim min As Date
    Dim max As Date

    ' Generate a random date from either range 1 or range 2.
    ' Randomly select either range 1 or range 2 by randomly 
    ' generating an odd or an even random number. 
    ' Check for odd or even
    If mRandomRange.Next() Mod 2 = 0 Then  
        min = mRange1Min
        max = mRange1Max
    Else
        min = mRange2Min
        max = mRange2Max
    End If

    ' The formula for creating a random number in a specific range is:
    ' start of range + (size of range * random number between 0 and 1)

    ' Size of range
    Dim range As TimeSpan = max - min

    ' (Size of range * random number between 0 and 1)
    Dim randomNumber As TimeSpan = _
        New TimeSpan(CLng(range.Ticks * mRandom.NextDouble()))

    ' Start of range + (size of range * random number between 0 and 1)
    mRandomDate = min + randomNumber

.NET Framework 安全性

请参见

参考

Generator 类

Microsoft.Data.Schema.Tools.DataGenerator 命名空间

GenerateNextValues