How can I generate random variables according to data types?

continuous random variable
types of random variable
random variable examples
discrete random variables
continuous random variable example
what is meant by random variable
random variable formula
discrete random variable example

I have some databases and tables. I am trying to detect data types of each column and create random variables according to data type?


For example:

col1 : int
col2 : nvarchar(max)
col3 : bit

I need to detect each of the data types in code and create random variables for insert.

Should I create a methods, which check all data types and generate variables, for this work? like:

if(datatype.Equals("int"))
   random.Next();
else if(datatype.Equals("string"))
   ...

Is there any easy way?



Here's an approach:

var random = new Random();
var factory = new Dictionary<Type, Func<object>>()
{
    { typeof(int), () => random.Next() },
    { typeof(string), () =>
        {
            var bytes = new byte[16];
            random.NextBytes(bytes);
            return Convert.ToBase64String(bytes);
        }
    },
    { typeof(DateTime), () => DateTime.Now.AddDays((random.NextDouble() - 0.5) * 100) },
};

Then you can do this:

var datatype = typeof(string);
var output = factory[datatype]();
Console.WriteLine(output);

I get eyqQ1EdMDTsR8Ny8kS73Hg== as an example output.

You just need to keep building up all of the types you need.

Random Variables, There are two types of random variables, discrete and continuous. The probability distribution of a discrete random variable is a list of A random number generator acting over an interval of numbers (a,b) has a continuous distribution. Discrete Random Variables. Discrete random variables can take on either a finite or at most a countably infinite set of discrete values (for example, the integers). Their probability distribution is given by a probability mass function which directly maps each value of the random variable to a probability.


There is no "SQL Server data type -> .NET data type" mapping table built-in; thus, you'll have to do the mapping yourself.

You can check SQL Server to .Net type conversions

Six Fundamental Methods to Generate a Random Variable – Win , Good references for the modern theory include: If we assume we can generate a random variable according to the distribution p(x) we can� Each of these types of variable can be broken down into further types. Quantitative variables. When you collect quantitative data, the numbers you record represent real amounts that can be added, subtracted, divided, etc. There are two types of quantitative variables: discrete and continuous.


The Random class provides Random.Next(), Random.NextBytes(), and Random.NextDouble() methods. The Random.Next() method returns a random number, Random.NextBytes() returns an array of bytes filled with random numbers, and Random.NextDouble() returns a random number between 0.0 and 1.0.

The Random.Next() method has three overloaded forms and allows you to set the minimum and maximum range of the random number.

The following code returns a random number.

int num = random.Next();

The following code returns a random number less than 1000.

int num = random.Next(1000);

The following code returns a random number between the min and the max range. To Generate a random number between two numbers

public int RandomNumber(int min, int max)  
{  
    Random random = new Random();  
    return random.Next(min, max);  
}

You can even combine the two methods - RandomNumber and RandomString to generate a combination of random string and numbers.

// Generate a random string with a given size  
public string RandomString(int size, bool lowerCase)  
{  
    StringBuilder builder = new StringBuilder();  
    Random random = new Random();  
    char ch;  
    for (int i = 0; i < size; i++)  
    {  
        ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65)));  
        builder.Append(ch);  
    }  
    if (lowerCase)  
        return builder.ToString().ToLower();  
    return builder.ToString();  
}

Reference

To know the mapping follow this Link

Use the GetType() method to know the data type in C#. You can learn about it Here

Random variables (video), There can be 2 types of Random variable Discrete and Continuous. Discrete which cannot Duration: 5:32 Posted: Dec 22, 2012 Types of Random Variables . A random variable can be either discrete or continuous. Discrete random variables take on a countable number of distinct values. Consider an experiment where a coin is


Random variable, In probability and statistics, a random variable, random quantity, aleatory variable , or stochastic on a randomly-generated number distributed uniformly on the unit interval. An example of a random variable of mixed type would be based on an experiment where a coin is according to the inverse function theorem. Data Types are an important concept of statistics, which needs to be understood, to correctly apply statistical measurements to your data and therefore to correctly conclude certain assumptions about it. This blog post will introduce you to the different data types you need to know, to do proper exploratory data analysis (EDA), which is one of the most underestimated parts of a machine


Random Variables, Capital Letters. We use a capital letter, like X or Y, to avoid confusion with the Algebra type of variable. Sample Space. A Random� Understanding statistics can help us see patterns in otherwise random looking data. Let’s discuss the 2 main types of random variables, and how to plot probability for each. What is a random variable. According to investopedia. A random variable is a variable whose value is unknown or a function that assigns values to each of an experiment


7.1.3 Generating Samples from Probability Distributions, a sample value, ys, of random variable Y can be generated. we be able to generate random sample values, ts, of the random variable X with the pdf The classical example of this type of approach is the generation of random observations� Numerical data can be further broken into two types: discrete and continuous. Discrete data represent items that can be counted; they take on possible values that can be listed out. The list of possible values may be fixed (also called finite ); or it may go from 0, 1, 2, on to infinity (making it countably infinite ).