MATLAB Code
clc;
clear all;
close all;
% Number of samples to generate
n = 100000;
% Generate Uniform distribution between 0 and 1
r = rand(1, n); % rand generates numbers in the range [0, 1]
% Transform to the range [-1, 1]
a = -1;
b = 1;
uniform_values = a + (b - a) * r;
% Plot the histogram of the generated uniform distribution
figure;
histogram(uniform_values, 30, 'Normalization', 'pdf'); % Normalized to show probability density
title('Uniform Distribution between -1 and 1');
xlabel('Value');
ylabel('Probability Density');
% Generate Gaussian distribution (Standard Normal Distribution)
gaussian_values = randn(1, n); % Standard normal distribution (mean = 0, std = 1)
% Plotting the Gaussian distribution
figure;
histogram(gaussian_values, 30, 'Normalization', 'pdf'); % Normalized to show probability density
title('Gaussian Distribution (Standard Normal)');
xlabel('Value');
ylabel('Probability Density');