random number generator to two different variables

I want to initialize two different random numbers to be assigned to different variables. If I put in:
x_1 = rand x_2 = rand
they will get exactly the same number. How do I assign two different random numbers?
Thanksr

 채택된 답변

Shane
Shane 2014년 11월 25일

0 개 추천

They get different random numbers for me. Which version of Matlab are you using?

댓글 수: 4

cgo
cgo 2014년 11월 25일
sorry for the confusion. When you are in the command window, then the two random numbers will be different. But when you are writing a script, the numbers will be the same.
Shane
Shane 2014년 11월 25일
Even when running as a script, they get different values for me.
cgo
cgo 2014년 11월 25일
alright. let me look into it.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Peter Perkins
Peter Perkins 2014년 11월 25일

1 개 추천

cgo, it may be that you have created a variable called "rand" in your workspace that is shadowing the rand function. The rand function does not return the same value two times in a row within the same MATLAB session.

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

cgo
2014년 11월 25일

답변:

2014년 11월 25일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by