cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X

How to use runif(1,1,7) in a program loop?

usit
1-Visitor

How to use runif(1,1,7) in a program loop?

This works:

jx:=10 j:=0..jx k:=0..2 x[j,k:=ceil(rnd(7)) x= displays a 3by10 mateix of integers 1,2,..7

This does not work: x[j,k:=ceil(runif(1,1,7)) x= displays a 3by10 matrix of [1,1] in every cell.

ceil(runif(1,1,7)) works by itself but not as I'm using it (above).

Any suggestions will be appreciated.

Ed

ACCEPTED SOLUTION

Accepted Solutions
AndyWesterman
12-Amethyst
(To:usit)

Hi Ed,

Rnd() returns a number so everything is OK,

Runif(,,,) returns a vector , so each element is saved as a 1x1 vector within the array.

In this case you can de-vectorise the number as:

ceil(runif(1,1,7)[0)

which seems to work for me

regards

Andy

View solution in original post

2 REPLIES 2
AndyWesterman
12-Amethyst
(To:usit)

Hi Ed,

Rnd() returns a number so everything is OK,

Runif(,,,) returns a vector , so each element is saved as a 1x1 vector within the array.

In this case you can de-vectorise the number as:

ceil(runif(1,1,7)[0)

which seems to work for me

regards

Andy

Made my day! Works perfectly.

Thanks Westerman, hope to return the favor some day.

Ed

Announcements

Top Tags