Is MATLAB's Randomization Function Affected by Appending Numbers to Student IDs?

  • Thread starter emergentecon
  • Start date
  • Tags
    Matlab
In summary, the conversation discusses the use of the "rand" command in Matlab to generate random numbers, specifically in the context of a homework assignment. The problem is that the same result is obtained regardless of what number is appended to the student number. The solution is to use the "rng" command instead to set the state.
  • #1
emergentecon
57
0

Homework Statement



Enter the following two commands, and copy and paste the output as your answer
> rand("state",student_number0917);
> rand(1)
where student_number0917 is your student number with "0917" at the end and with "-" removed.
For example, if your student number is 123-456-7, you would enter
> rand("state",12345670917);
> rand(1)


The problem is, we need to do this for each new assignment, and for each new assignment, we append a new number: 0917 (in this instance), then 0913, 0920, 0911 etc.

However, I always get the same result, no matter what number I append?
Am I missing something?

Homework Equations



> rand("state",1234567?);
> rand(1)

The Attempt at a Solution



>> clc; clear;
>> rand('state',312754190917)
>> rand(1)

ans =

0.662733934182293

OR


>> clc; clear;
>> rand('state',312754190913)
>> rand(1)

ans =

0.662733934182293
 
Physics news on Phys.org
  • #3
Yeah, that is the exact version I am using . . . cool, will look into it!
I have emailed my Prof. (included your post) :)

Thanks!
 

FAQ: Is MATLAB's Randomization Function Affected by Appending Numbers to Student IDs?

What is "MATLAB Simple Randomization"?

"MATLAB Simple Randomization" refers to the process of generating random numbers or selecting random elements from a given data set in MATLAB. This can be useful for creating randomized experiments or simulations, as well as for testing and validating algorithms.

How do I generate random numbers in MATLAB?

To generate random numbers in MATLAB, you can use the "rand" function. This function creates a matrix of random numbers between 0 and 1. You can also use the "randi" function to generate random integers within a specified range, or the "randn" function to generate random numbers from a normal distribution.

Can I control the range of random numbers in MATLAB?

Yes, you can use the "rand" function with a specified range to generate random numbers within that range. For example, "rand(1,10)*10" will generate a matrix of 10 random numbers between 0 and 10.

How do I select random elements from a data set in MATLAB?

To select random elements from a data set in MATLAB, you can use the "randperm" function. This function creates a random permutation of the elements in a given data set. You can also use the "randi" function to randomly select a specified number of elements from a data set.

Is there a way to replicate or save a specific set of random numbers in MATLAB?

Yes, you can use the "rng" function to set the seed for the random number generator in MATLAB. This allows you to replicate or save a specific set of random numbers by using the same seed value. You can also use the "save" function to save a specific set of random numbers as a variable in a MATLAB file.

Similar threads

Replies
4
Views
4K
Replies
1
Views
9K
Replies
5
Views
3K
Replies
10
Views
5K
Replies
1
Views
6K
Replies
2
Views
3K
Back
Top