Share via


Generator.OnGenerateNextValues Method

Generates the next value according to the data generation algorithm.

Namespace:  Microsoft.Data.Schema.Tools.DataGenerator
Assembly:  Microsoft.Data.Schema.Tools (in Microsoft.Data.Schema.Tools.dll)

Syntax

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

Remarks

The OnGenerateNextValues method creates the data when a data generation plan runs. You must override this method to provide the logic that generates the data for the output properties of your data generator.

The GenerateNextValues method calls this method. To modify the functionality of the GenerateNextValues, you must override the OnGenerateNextValues.

Examples

This example overrides the OnGenerateNextValues method to generate the random data for a data generator. This code sample is part of a larger example provided for the Generator class.

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 Security

See Also

Reference

Generator Class

Microsoft.Data.Schema.Tools.DataGenerator Namespace

GenerateNextValues