.NET Matrix Library
FillRandom(Double,Double,Int32) Method
See Also  Example Send Feedback



lowerBound
A double specifying the lower limit of the random values that will be used.
upperBound
A double specifying the upper limit of the random values that will be used.
decimals
An integer specifying the number of decimal places to which random values will be rounded to.
Fills CMatrix object with random values ranging from lower bound to upper bound, rounded to the specified number of decimal places.

Syntax

Visual Basic (Declaration) 
Public Overloads Sub FillRandom( _
   ByVal lowerBound As Double, _
   ByVal upperBound As Double, _
   ByVal decimals As Integer _
) 
Visual Basic (Usage)Copy Code
Dim instance As CMatrix
Dim lowerBound As Double
Dim upperBound As Double
Dim decimals As Integer
 
instance.FillRandom(lowerBound, upperBound, decimals)
C# 
public void FillRandom( 
   double lowerBound,
   double upperBound,
   int decimals
)
C++/CLI 
public:
void FillRandom( 
   double lowerBound,
   double upperBound,
   int decimals
) 

Parameters

lowerBound
A double specifying the lower limit of the random values that will be used.
upperBound
A double specifying the upper limit of the random values that will be used.
decimals
An integer specifying the number of decimal places to which random values will be rounded to.

Example

The following example demonstrates the use of the FillRandom and ToString methods.
Visual BasicCopy Code
Imports System
Imports Bluebit.MatrixLibrary

Class Test

    Public Shared Sub Main()

        'Declaring a 4x4 Matrix
        Dim A As New CMatrix(4, 2)
        'Fill matrix A with random values from 0 to 10
        A.FillRandom()
        'Print the matrix using the default format
        Console.WriteLine(A)
        'Print the matrix with 0 decimal digits
        Console.WriteLine(A.ToString("F0"))

        'Fill matrix with random values ranging from 
        ' - 100 to 100 with 3 decimals
        A.FillRandom(-10000, 10000, 3)
        'Print the matrix with 2 decimal digits
        Console.WriteLine(A.ToString("F2"))
        'Print the matrix in scientific format 3 decimals
        Console.WriteLine(A.ToString("E3"))
        'Print the matrix in roundtrip format and in array declaration style
        Console.WriteLine(A.ToString("R", ",", "{", "}," + vbCrLf, "}" + vbCrLf))
        'Print the matrix using a different culture info (Italian)
        Dim cInfo As System.Globalization.CultureInfo = New System.Globalization.CultureInfo("it-IT")
        Console.WriteLine(A.ToString(cInfo, "N"))

        Console.Read()
    End Sub

End Class
C#Copy Code
using System;
using Bluebit.MatrixLibrary;

class Test
{
	static void Main(string[] args)
	{

        //Declaring a 4x4 Matrix 
        CMatrix A = new CMatrix(4, 2);
        //Fill matrix A with random values from 0 to 10
        A.FillRandom();
        //Print the matrix using the default format
        Console.WriteLine(A);
        //Print the matrix with 0 decimal digits
        Console.WriteLine(A.ToString("F0"));

        //Fill matrix with random values ranging from 
        // - 10000 to 10000 with 3 decimals
        A.FillRandom(-10000, 10000, 3);
        //Print the matrix with 2 decimal digits
        Console.WriteLine(A.ToString("F2"));
        //Print the matrix in scientific format with 3 decimals
        Console.WriteLine(A.ToString("E3"));
        //Print the matrix in roundtrip format and in array declaration style
        Console.WriteLine(A.ToString("R", ",", "{", "},\n", "}\n"));
        //Print the matrix using a different culture info (Italian)
        System.Globalization.CultureInfo  cInfo = new System.Globalization.CultureInfo("it-IT");
        Console.WriteLine(A.ToString(cInfo, "N"));
        
        Console.Read();
	}
}
C++Copy Code
#include "stdafx.h"

using namespace System;
using namespace Bluebit::MatrixLibrary;

int main(array<System::String ^> ^args)
{
	//Declaring a 4x4 Matrix  
	CMatrix^ A = gcnew CMatrix(4, 2);
	//Fill matrix A with random values from 0 to 10
	A->FillRandom();
	//Print the matrix using the default format
	Console::WriteLine(A);
	//Print the matrix with 0 decimal digits
	Console::WriteLine(A->ToString("F0"));

	//Fill matrix with random values ranging from 
	// - 10000 to 10000 with 3 decimals
	A->FillRandom(-10000, 10000, 3);
	//Print the matrix with 2 decimal digits
	Console::WriteLine(A->ToString("F2"));
	//Print the matrix in scientific format with 3 decimals
	Console::WriteLine(A->ToString("E3"));
	//Print the matrix in roundtrip format and in array declaration style
	Console::WriteLine(A->ToString("R", ",", "{", "},\n", "}\n"));
	//Print the matrix using a different culture info (Italian)
	System::Globalization::CultureInfo^  cInfo = gcnew System::Globalization::CultureInfo("it-IT");
	Console::WriteLine(A->ToString(cInfo, "N"));

	Console::Read();

	return 0;
}
k

Remarks

Use FillRandom method in order to quickly fill the matrix with random values, while coding, testing and debugging your application.

Requirements

Target Platforms: Windows 2000, Windows XP, Windows Server 2003 family, Windows Vista, Windows Server 2008 family, Windows 7

See Also

.NET Matrix Library