cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
lisamaley
Level III

set variable to random number.

I want to set variables to random numbers.    I tried this. but it is not working

 

 

MEnum = 5;
For( i = 1, i = MEnum, i++,
	betai = Random uniform.( 30, 50 )
);

 

 

When I print this to the log it just keeps giving me random numbers, how do I get 5 different random numbers for beta1 to beta5?

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: set variable to random number.

I would do it this way

beta = {};
MEnum = 5;
for (i=1,  I<=MEnum,i++,
      beta[i] = Random uniform. (30,50);
);

 

Jim

View solution in original post

6 REPLIES 6
txnelson
Super User

Re: set variable to random number.

I would do it this way

beta = {};
MEnum = 5;
for (i=1,  I<=MEnum,i++,
      beta[i] = Random uniform. (30,50);
);

 

Jim
Craige_Hales
Super User

Re: set variable to random number.

and change i=MEnum to i<=MEnum

Craige
lisamaley
Level III

Re: set variable to random number.

I tried

beta = {};
For( i = 1, i <= MEnum, i++,
	beta[i] = Random uniform.( 30, 50 );
	Print( betai );
);



MEnum is based on how many columns are selected. I checked this out and it is working.

but I get this error:

Name Unresolved: Random uniform. in access or evaluation of 'Random uniform.' , Random uniform.( 30, 50 ) /*###*/

lisamaley
Level III

Re: set variable to random number.

I tried 

 

 

beta = {};
For( i = 1, i <= MEnum, i++,
	beta[i] = Random uniform.( 30, 50 );
	Print( betai );

);

 

MEnum is defined above all this and is working fine.

But I am getting this error:

 

Name Unresolved: Random uniform. in access or evaluation of 'Random uniform.' , Random uniform.( 30, 50 ) /*###*/

lisamaley
Level III

Re: set variable to random number.

Nevermind, I took out your period and it works.  I copied without paying attention.  thank you!

 

Re: set variable to random number.

Very nice lesson, @txnelson . I would also offer this way:

 

beta = J( MEnum, 1, Random Uniform( 30, 50 ) );