Share your ideas for the JMP Scripting Unsession at Discovery Summit by September 17th. We hope to see you there!
Choose Language Hide Translation Bar
Highlighted
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
Highlighted
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
Highlighted
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

Highlighted
Craige_Hales
Staff (Retired)

Re: set variable to random number.

and change i=MEnum to i<=MEnum

Craige
Highlighted
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 ) /*###*/

Highlighted
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 ) /*###*/

Highlighted
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!

 

Highlighted

Re: set variable to random number.

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

 

beta = J( MEnum, 1, Random Uniform( 30, 50 ) );
Learn it once, use it forever!
Article Labels