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.
Shane
Shane 2014 年 11 月 25 日

サインインしてコメントする。

その他の回答 (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 ExchangeCreating 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