Share via


Generator.OnGenerateNextValues Method

Generates the next value according to the data generation algorithm.

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

Syntax

'Declaration
Protected Overridable Sub OnGenerateNextValues
'Usage

Me.OnGenerateNextValues()
protected virtual void OnGenerateNextValues()
protected:
virtual void OnGenerateNextValues()
protected function OnGenerateNextValues()
abstract OnGenerateNextValues : unit -> unit 
override OnGenerateNextValues : unit -> unit 

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. You should override OnGenerateNextValues if you want to override the GenerateNextValues functionality.

Examples

This example overrides the OnGenerateNextValues method to generate the random data for a data generator. This code example 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.
    '------------------------------------------------------------
    If mRandomRange.Next() Mod 2 = 0 Then  'check for odd or even
        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

Generator Members

Microsoft.Data.Schema.DataGenerator Namespace