clc clear n=63;%the number of servers request_n=3000; %the number of request %An example of an IPv6 address is '2001:0DB8: 0000:0000:0008:0800:200C:417A'. D = hex2dec('FFFFFFFFFFFF'); %the first 12 digit in client IP address client_IP_rand = randi([0 D],1,request_n, 'single'); %%Example of a hash function based on mid-square sqr_client_IP_rand=client_IP_rand.^2; %square the client IP address st2= compose("%9.0f",sqr_client_IP_rand); % convert number to string for i=1:request_n-1 L=strlength(st2(i)); mid1=round(L./2); mid2=mid1+1; st=st2{1,i}(mid1:mid2); %used as key, the mid digit of the square client IP address hash_mid_square(i)=str2num(st); end hash_mid_square=mod(hash_mid_square,n); subplot (121);
clc clear n=63;%the number of servers request_n=3000; %the number of request %An example of an IPv6 address is '2001:0DB8: 0000:0000:0008:0800:200C:417A'. D = hex2dec('FFFFFFFFFFFF'); %the first 12 digit in client IP address client_IP_rand = randi([0 D],1,request_n, 'single'); %%Example of a hash function based on mid-square sqr_client_IP_rand=client_IP_rand.^2; %square the client IP address st2= compose("%9.0f",sqr_client_IP_rand); % convert number to string for i=1:request_n-1 L=strlength(st2(i)); mid1=round(L./2); mid2=mid1+1; st=st2{1,i}(mid1:mid2); %used as key, the mid digit of the square client IP address hash_mid_square(i)=str2num(st); end hash_mid_square=mod(hash_mid_square,n); subplot (121);
A First Course in Probability (10th Edition)
10th Edition
ISBN:9780134753119
Author:Sheldon Ross
Publisher:Sheldon Ross
Chapter1: Combinatorial Analysis
Section: Chapter Questions
Problem 1.1P: a. How many different 7-place license plates are possible if the first 2 places are for letters and...
Related questions
Question
![clc
clear
n=63;%the number of servers
request_n=3000; %the number of request
%An example of an IPv6 address is '2001:0DBS: 0000:0000:0008:0800:200C: 417A¹.
D = hex2dec ('FFFFFFFFFFFF'); %the first 12 digit in client IP address
client_IP_rand = randi([ D],1,request_n, 'single');
%%Example of a hash function based on mid-square
sqr_client_IP_rand=client_IP_rand.^2;
%square the client IP address
st2= compose("%9.0f",sqr_client_IP_rand); % convert number to string
for i=1:request_n-1
L=strlength(st2(i));
end
mid1=round (L./2);
mid2=mid1+1;
st=st2{1,i}(mid1:mid2);%used as key, the mid digit of the square client IP address
hash_mid_square(i)=str2num(st);
hash_mid_square=mod(hash_mid_square,n);
subplot (121);
histogram(hash_mid_square,n);
mean_mid_square= mean(hash_mid_square);
std_mid_square=std(hash_mid_square);
%%Example of a hash function h(x)=((ax +b)mod(p))mod(n)
% Modular Arithmetic
p= 274988895429719;% prime number
a=100;
b=10;
hash_f=mod(a.*client_IP_rand+b,p); % Hash function based on Modular Arithmetic
hash_f=mod (hash_f,n);
subplot (122) ;histogram(hash_f,n);
mean_Modular =mean(hash_f);
std_Modular= std(hash_f);](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F7079c663-ec07-4d0d-90c3-e86ff6bb1397%2F4d82143c-3ab0-4b0a-bf17-22230e4b84c5%2Fy3es64f_processed.png&w=3840&q=75)
Transcribed Image Text:clc
clear
n=63;%the number of servers
request_n=3000; %the number of request
%An example of an IPv6 address is '2001:0DBS: 0000:0000:0008:0800:200C: 417A¹.
D = hex2dec ('FFFFFFFFFFFF'); %the first 12 digit in client IP address
client_IP_rand = randi([ D],1,request_n, 'single');
%%Example of a hash function based on mid-square
sqr_client_IP_rand=client_IP_rand.^2;
%square the client IP address
st2= compose("%9.0f",sqr_client_IP_rand); % convert number to string
for i=1:request_n-1
L=strlength(st2(i));
end
mid1=round (L./2);
mid2=mid1+1;
st=st2{1,i}(mid1:mid2);%used as key, the mid digit of the square client IP address
hash_mid_square(i)=str2num(st);
hash_mid_square=mod(hash_mid_square,n);
subplot (121);
histogram(hash_mid_square,n);
mean_mid_square= mean(hash_mid_square);
std_mid_square=std(hash_mid_square);
%%Example of a hash function h(x)=((ax +b)mod(p))mod(n)
% Modular Arithmetic
p= 274988895429719;% prime number
a=100;
b=10;
hash_f=mod(a.*client_IP_rand+b,p); % Hash function based on Modular Arithmetic
hash_f=mod (hash_f,n);
subplot (122) ;histogram(hash_f,n);
mean_Modular =mean(hash_f);
std_Modular= std(hash_f);

Transcribed Image Text:Task 2:
Evaluate probability theory to an example involving hashing and load balancing.
Consider the MATLAB code named 'Hash_Spring2023'. In this code, we defined two Hash functions:
one using the Mid-square method and the other using Modular Arithmetic. In either method, the
client's IP address is used as the input of the Hash function.
A. For the Hash function defined based on the Mid-square method, study the distribution Y of the
clients' requests across the n servers by doing the following:
(i) Simulating a sample of at least 20000 outcomes for Y.
(ii) Plotting a histogram showing the approximate distribution of Y.
(iii) Calculating the mean and the standard deviation of the sample.
B. Repeat part 'A', but now for the Hash function defined based on Modular Arithmetic.
C. Explain and compare the results you found for the Hash functions in parts 'A' and 'B'.
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 3 steps

Recommended textbooks for you

A First Course in Probability (10th Edition)
Probability
ISBN:
9780134753119
Author:
Sheldon Ross
Publisher:
PEARSON


A First Course in Probability (10th Edition)
Probability
ISBN:
9780134753119
Author:
Sheldon Ross
Publisher:
PEARSON
