###
Mid Square Method Code implementation in C and MatLab:

###
Problem:

Mid square method, mid square random number generator Code in MatLab and C or C++.

###
Solution:

####
Mid Square Random Number Generator Code in C:

#include<stdio.h>
int main()
{
long int seed = 6897; int i, n, random;
printf("How many number you want to generate : ");
scanf("%d", &n);
printf("Random Numbers are : ");
for(i = 0; i < n; i++)
{
seed = seed * seed;
seed = seed / 100; seed = seed % 10000; random = seed;
printf("%d ", random);
}
printf("\n");
return 0;
}

####
Output of the Mid Square Random Number Generator code in C:

###
Mid Square Random Number Code in Matlab:

%% Problem : Random Number Generator ---> Mid Square Method %%
% Author : Maniruzzaman Akash
totalNumber = input('Number of Random Numbers want to generate : ');
choose = input('Enter the seed : ');
disp('Total Random Numbers are : ');
for i = 1:totalNumber
random = choose ^ 2;
random = random / 100; % Find the dividend
random = rem(random, 10000); % Get the reminder;
choose = random;
fprintf('%.2f ', random);
end
fprintf('\n');

###
Procedure of Mid Square Method Random Number Generator:

- Take the first seed or first random number.
- Square it.
- Take the middle from the 8 digits square value
- divide it by 100 first then
- take the reminder of 10000 of that value again
- Finally result will present in the seed or in random.

###
Tags:

Numerical Methods, Simulation and Modeling, C Programming, MatLab Code, Mid Square Method Code, Midsquare code implementation,

I really appreciate this article, and please may I ask you to translate to English another one, ok? You will literally save my life! Currently I have faced a lot of problems with my programming dissertation as it consists of two parts, technical and preface writing. As a tech person I can't write anything at all. So I am trying to get help from https://findmywriters.com/top-quality-essay-writing-services/ this blog but I would like to ask you, have you ever faced such a requirement?

ReplyDelete