using the mod function to create and even random number generator in matlab

using the vector i created called random20
random20 = randi ([0,100],1,20);
how do i use the mod function to get all even random integers
any help would be appreciated.

2 件のコメント

James Tursa
James Tursa 2020 年 1 月 27 日
編集済み: James Tursa 2020 年 1 月 27 日
Hint: What does mod(random20,2) give you? Can you use that to get the even ones?
Alex  Perez
Alex Perez 2020 年 1 月 27 日
when i use mod(random20,2) i get 0's and 1's in my output
here is my code
Annotation 2020-01-27 163440.png

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

回答 (1 件)

John D'Errico
John D'Errico 2020 年 1 月 27 日

0 投票

Why do you need the mod function? Just generate random integers, and then MULTIPLY THEM BY 2.

カテゴリ

ヘルプ センター および File ExchangeRandom Number Generation についてさらに検索

タグ

質問済み:

2020 年 1 月 27 日

回答済み:

2020 年 1 月 27 日

Community Treasure Hunt

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

Start Hunting!

Translated by