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
011717
Level II

Get random numbers upon radio button selection

Hi, 

I am trying to produce random numbers upon radio box selection and produce a number of combination according to user input. So far, this is what I only have.

win = New Window( "LOTTO",
	<<Modal,
	Panel Box( "Select one",
		rb = Radio Box( 
				{"6/42", "6/45", "6/49", "6/55", "6/58"} ),
			Text Box( "Enter Number of Combinations" ),
			H List Box( Text Box( "" ), 
				textbox_value = Number Edit Box(1) ),
		Button Box( "Ok", 
					rb_result = rb << get; 
					random = textbox_value << get; 
					
		);	
	) 
);
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

Re: Get random numbers upon radio button selection

It is still not clear to me what you want to do but see if this result is close.

 

Names Default To Here( 1 );

win = New Window( "LOTTO", << Modal,
	Panel Box( "Select one",
		rb = Radio Box( {"6/42", "6/45", "6/49", "6/55", "6/58"} ),
		H List Box(
			Text Box( "Enter Number of Combinations" ),
			textbox_value = Number Edit Box( 1 )
		)
	),
	H List Box(
		Button Box( "OK",
			rb_result = rb << Get;
			random = textbox_value << Get; 
					
		),
		Button Box( "Cancel" )
	)
);

If( win["Button"] == -1,
	Throw( "User cancelled" )
);

dt = New Table( "Lotto" );

For( c = 1, c <= random, c++,
	dt << New Column( "Draw " || Char( c ),
		"Numeric",
		"Continuous",
		Values(
			Choose( rb_result,
				J( 6, 1, Random Integer( 1, 42 ) ),
				J( 6, 1, Random Integer( 1, 45 ) ),
				J( 6, 1, Random Integer( 1, 49 ) ),
				J( 6, 1, Random Integer( 1, 55 ) ),
				J( 6, 1, Random Integer( 1, 58 ) )
			)
		)
	);
);
Learn it once, use it forever!

View solution in original post

3 REPLIES 3
Highlighted

Re: Get random numbers upon radio button selection

I don't play lotteries so I don't know how to interpret choices like "6/42." Does it mean draw 6 numbers with replacement from 1 to 42?

 

Anyway, your window as almost complete. Also, you need to check if the user wants to continue. Then use the index obtained from the radio box to proceed. The Choose() function is exactly the right one to use in this case.

 

Names Default To Here( 1 );

win = New Window( "LOTTO",
	<<Modal,
	Panel Box( "Select one",
		rb = Radio Box( {"6/42", "6/45", "6/49", "6/55", "6/58"} ),
		H List Box(
			Text Box( "Enter Number of Combinations" ),
			textbox_value = Number Edit Box( 1 )
		),
		H List Box(
			Button Box( "OK",
				rb_result = rb << Get;
				random = textbox_value << Get; 
						
			),
			Button Box( "Cancel" )
		)
	)
);

If( win["Button"] == -1,
	Throw( "User cancelled" )
);

Choose( rb_result,
	// add arguments here that depend on the choice from the radio box
);

// don't know what you want to do from here on.
Learn it once, use it forever!
Highlighted
011717
Level II

Re: Get random numbers upon radio button selection

If the user chose 6/42, it will generate 6 random numbers from 1-42 only.
Highlighted

Re: Get random numbers upon radio button selection

It is still not clear to me what you want to do but see if this result is close.

 

Names Default To Here( 1 );

win = New Window( "LOTTO", << Modal,
	Panel Box( "Select one",
		rb = Radio Box( {"6/42", "6/45", "6/49", "6/55", "6/58"} ),
		H List Box(
			Text Box( "Enter Number of Combinations" ),
			textbox_value = Number Edit Box( 1 )
		)
	),
	H List Box(
		Button Box( "OK",
			rb_result = rb << Get;
			random = textbox_value << Get; 
					
		),
		Button Box( "Cancel" )
	)
);

If( win["Button"] == -1,
	Throw( "User cancelled" )
);

dt = New Table( "Lotto" );

For( c = 1, c <= random, c++,
	dt << New Column( "Draw " || Char( c ),
		"Numeric",
		"Continuous",
		Values(
			Choose( rb_result,
				J( 6, 1, Random Integer( 1, 42 ) ),
				J( 6, 1, Random Integer( 1, 45 ) ),
				J( 6, 1, Random Integer( 1, 49 ) ),
				J( 6, 1, Random Integer( 1, 55 ) ),
				J( 6, 1, Random Integer( 1, 58 ) )
			)
		)
	);
);
Learn it once, use it forever!

View solution in original post

Article Labels

    There are no labels assigned to this post.