Skip to first unread message

Stuart Buchan

unread,
Oct 26, 2018, 12:03:37 PM10/26/18
to MIT App Inventor Forum
Hi Guys/Gals

As the Euromillions Lottery is sitting at £63M tonight, I thought I'd pop up my amended Lotto App (.aia) - original taken from Mike McGrath's "Building Android Apps no coding required!" book. His (.aia attached) was for the UK Lottery, mine is for Euromillions.
I just duplicated his blocks but changed the elements to suit and to accommodate the additional draw of two stars. I've tried to do this in a loop with variables changing using If-Then-Else blocks for main balls and stars but I didn't get the results I expected or it went into a never-ending loop.

I'm sure there must be a way of doing this more efficiently. I'm also planning to give the user a choice between UK & EuroMs games or do both. I'd be grateful for any suggestions.

BTW: If anybody uses this and wins with the generated numbers, an acknowledgement of yours truly would be brilliant! ;-)

Cheers, Stuart
EuroMs.aia
Lotto.aia

Abraham Getzler

unread,
Oct 27, 2018, 6:00:45 PM10/27/18
to MIT App Inventor Forum
You shuffle a list of 49 items, using one pass to load 49 numbers
and a second pass to shuffle it.

The attached app should run about 10 times faster,
on the average.

ABG


Capture.PNG
Capture1.PNG
Capture2.PNG
pick6.aia
blocks.png

Stuart Buchan

unread,
Oct 29, 2018, 7:26:54 PM10/29/18
to mitappinv...@googlegroups.com

(Re-)posted here, as inadvertantly sent to Abraham's email, as I replied on  my phone!


Thanks Abraham!


That's great advice for the basic Lotto selection. My query was about how to use the same procedure to select a separate set of numbers (as per my EuroMs.aia).

I tried a For loop with an If-Then-Else block, using a variable as the number but nothing worked. I set the variable then changed it after the first iteration but I either got a never-ending loop or a 1-5 sequence for the first set and a random selection for the second set. I tried a While block too but got similar results.

I'll have another go and post my attempts, unless you or others can suggest how to achieve my goal in the meantime.


TIA


Stuart

Abraham Getzler

unread,
Oct 29, 2018, 8:42:35 PM10/29/18
to MIT App Inventor Forum
Can you describe for us how the EuroMillions lottery works?

I see 7 Labels for number choices.

For each Label, what is the range of numbers that can go in it?

Are duplicate values allowed?

ABG

Chris Ward

unread,
Oct 30, 2018, 5:36:57 AM10/30/18
to MIT App Inventor Forum
Five 'main' numbers, selected from 1-50. Two 'lucky stars' selected from 1-12. Numbers in the 'luck stars' can duplicate numbers in the 'main'.

Abraham Getzler

unread,
Oct 30, 2018, 12:00:04 PM10/30/18
to MIT App Inventor Forum
Two 'lucky stars' selected from 1-12. Numbers in the 'luck stars' can duplicate numbers in the 'main'.

Can the two lucky stars duplicate each other?

ABG
 

Abraham Getzler

unread,
Oct 30, 2018, 12:37:40 PM10/30/18
to MIT App Inventor Forum
See attached.

I assumed no duplication within the lucky stars.

ABG

blocks.png
Capture.PNG
Designer.PNG
pick52.aia
pick52.PNG

Chris Ward

unread,
Oct 30, 2018, 1:20:18 PM10/30/18
to MIT App Inventor Forum
Assumption correct :)

Stuart Buchan

unread,
Oct 30, 2018, 2:19:00 PM10/30/18
to MIT App Inventor Forum
Briliant Abraham!

I actually managed to get it to work using a procedure and passing variables to it (see attached) but your solution is fantastic and so neat and tidy. WOW!

Cheers, Stuart
Blocks.jpg
Display.jpg

Stuart Buchan

unread,
Oct 30, 2018, 2:22:24 PM10/30/18
to MIT App Inventor Forum
Thanks for pointing out that it was a 1-50 selection for the first five numbers, Chris!
My .aia was therefore incomplete and not a valid option to play the Euromillions that night. ;-)

SteveJG

unread,
Oct 30, 2018, 4:06:33 PM10/30/18
to MIT App Inventor Forum
Are you aware your  Random Number isn't random; it is pseudo-random.  JDK1.7 doc says :Returned values are chosen pseudorandomly with (approximately) uniform distribution from that range.   Setting a random seed using the  random set seed to    block and setting to a day number so it changes every day might improve randomness (or using a different method to provide a different seed when the app is run.... day number plus the Clock now seconds perhaps?)..


random set seed to

Use this block to generate repeatable sequences of random numbers. You can generate the same sequence of random numbers by first calling random set seed with the same value. This is useful for testing programs that involve random values.


If you keep changing the seed, the numbers are no longer repeatable. With a seed you can generate the same results and by using different seeds , you can guarantee that a different number sequence will be generated.


Does it makes a difference?  I have no idea.  Perhaps others will comment.


Regards,

Steve

Stuart Buchan

unread,
Oct 30, 2018, 5:17:44 PM10/30/18
to MIT App Inventor Forum
Thanks Steve!

Great info. I'll remember that for testing in future and making the RNG more sophisticated.

Cheers, Stuart

Stuart Buchan

unread,
Nov 1, 2018, 8:10:28 AM11/1/18
to MIT App Inventor Forum
Hi

Please see the attached image of my Clear block.

Is it possible to create a procedure to set the labels to nulls by using "Label" and then appending 1-13 in a loop?

Cheers, Stuart
ClearBlock.jpg

Abraham Getzler

unread,
Nov 1, 2018, 12:47:48 PM11/1/18
to MIT App Inventor Forum
See my https://docs.google.com/document/d/1RbPhI6cnHz3pRfqpEOVtRoMdkQlEA3Qm5BtuYq4bbGY/edit?usp=sharing
sample for how I use the Any Button blocks to scroll 3 buttons through a list of .Text values and button colors.

Notice the buttons value procedure I included to return a list of all my buttons.

You would need a Labels procedure for your labels, and the Any Label blocks.

They are in a separate section of the Blocks palette.

Post your latest .aia if you need a sample.

ABG

Chris Ward

unread,
Nov 1, 2018, 1:00:29 PM11/1/18
to MIT App Inventor Forum
Hello Stuart

If you are only going to loop the Labels to clear them, there is not really any advantage in having a loop as you still have to create a list of the labels at runtime to enable that loop.

Stuart Buchan

unread,
Nov 1, 2018, 1:33:10 PM11/1/18
to MIT App Inventor Forum
Thanks Chris! I wondered about that. ;-)

Stuart Buchan

unread,
Nov 1, 2018, 1:36:16 PM11/1/18
to MIT App Inventor Forum
Thanks again Abraham. I'll check it out.
Chris pointed out that there would be no real advantage to clearing them with a loop. I just thought I could use the number sequence something like this :

For i=1 to 13
  set "Label" & i to " "
Next i

Cheers, Stuart

Italo

unread,
Nov 1, 2018, 1:37:43 PM11/1/18
to mitappinv...@googlegroups.com
I really wish somebody would add a StringToComponent block, so we can "construct" the component ID name by joining strings.
May be some extension developer...

Stuart, Chris is right, you can do it by creating a list of components ID's but in the end it will be the same amount of work if you only do it to clear their contents.

If you still decide you want to do it, Taifun once showed us a way to do it, by using the "Lookup in Pairs" block.

Basically you create a list of lists. Each "sublist" has the string and the component ID.
You search for the key any way you want (by joining strings for example) and you get the component ID.



Capture.JPG





Abraham Getzler

unread,
Nov 1, 2018, 1:39:15 PM11/1/18
to MIT App Inventor Forum
You are doing more than clearing your labels, right?

You are also loading them from matching list elements after 
generating your random numbers.  

That would pay for the list of labels procedure block count.

for i = 1 to length of list (call all_labels)
  set Label.Text of (select item i from list (call all_labels)) to select item i from list picks
end for

ABG

Stuart Buchan

unread,
Nov 1, 2018, 2:23:14 PM11/1/18
to MIT App Inventor Forum
Spot on Abraham!

Boban Vukovic

unread,
Nov 1, 2018, 5:51:27 PM11/1/18
to mitappinv...@googlegroups.com
I made this app some time ago and it may be interesting because it uses sprites and sorts numbers at the end.


PS balls spacing (size) is not adjusted (it is for my screen size !) so  there might be some overlapping or under sizing for different screen sizes 
loterry.aia

Stuart Buchan

unread,
Nov 2, 2018, 6:22:45 AM11/2/18
to MIT App Inventor Forum
Hi Steve

I'm interested in using this "random set seed to" block but can't discover how to utilise it.
My assumption is that it overrides the built-in pseudo RNG procedures with the seed being set first. So If I apply any other random block afterwards, it will use the seed to generate the number. Is that correct?
If that is the case, I can't see how to connect the seed block to another random block. If not, how does it work?

Any examples?


Cheers, Stuart

SteveJG

unread,
Nov 2, 2018, 8:16:52 AM11/2/18
to mitappinv...@googlegroups.com
I do not think the block overrides the pseudo random distribution, it only adds an additional layer of randomness or repeatability depending on how it is used.  It seems if you use it with a static seed, your app should repeat every time you start fresh.  If you change the seed (presumably with a pseudo random number... something like the current time in seconds) it should start with a different seed if the block is placed as the initial block in your routine that calls for a random number.   Does it really provide a real random number?  No.  What it does is adds an additional 'layer' of randomness. I can't prove that.


Stuart Buchan

unread,
Nov 2, 2018, 8:44:08 AM11/2/18
to MIT App Inventor Forum
Hi Steve

I worked out how to use it and have created this block to test it. To ensure that the seed worked, I input a value instead of the Clock1 block and it repeated every time Button1 was pressed.

Random.jpg







This random seed method works a treat!

Cheers, Stuart

SteveJG

unread,
Nov 2, 2018, 8:50:17 AM11/2/18
to MIT App Inventor Forum
Glad that works the way you want.  Thanks for posting your blocks so others can see how you did it.
Message has been deleted

Stuart Buchan

unread,
Nov 2, 2018, 9:24:25 AM11/2/18
to MIT App Inventor Forum
No problem Steve. In fact, here's the .aia with modifications. There are a few more I'd like to make but thus far, I'm happy with it.
Suggestions for improvements most welcome!

Cheers, Stuart
LottoPick.aia

Stuart Buchan

unread,
Nov 2, 2018, 9:30:56 AM11/2/18
to MIT App Inventor Forum
Love it Boban!

I had thought about doing something similar. I've already started doing some of the ball images on Photoshop.
I'll look at your blocks for some ideas ;-) !

Cheers, Stuart

Boban Vukovic

unread,
Nov 2, 2018, 1:06:49 PM11/2/18
to MIT App Inventor Forum
actually I stole (borrowed!) my balls images from Finish(like Finland) lottery

Boban Vukovic

unread,
Nov 2, 2018, 1:12:55 PM11/2/18
to MIT App Inventor Forum
One more thing,if you are adding random numbers to a list and then generate next number,check if it is in list,if it is,generate another one... In my opinion you loose a bit of "randomness"!
Much better to remove random number from a list,and generate another one only from numbers remaining.
and set seed to seconds,or even better milliseconds from system clock 

Abraham Getzler

unread,
Nov 2, 2018, 2:10:32 PM11/2/18
to MIT App Inventor Forum
if you are adding random numbers to a list and then generate next number,check if it is in list,if it is,generate another one... In my opinion you loose a bit of "randomness"!
Much better to remove random number from a list,and generate another one only from numbers remaining.

Uh oh, are you bringing up the Monty Hall problem?

This is way beyond my pay grade.

ABG


Boban Vukovic

unread,
Nov 2, 2018, 2:40:27 PM11/2/18
to MIT App Inventor Forum
Never heard for that problem before,but explanation is fascinating!


PS what if I love goats?
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted

Italo

unread,
Nov 2, 2018, 5:39:25 PM11/2/18
to mitappinv...@googlegroups.com

About taking the numbers from a single pool to avoid the problem mentioned above, here’s a procedure I made some time ago to create a list of random numbers, with these options

Minimum
Maximum
How many numbers
Repeat or unique numbers
Sorted or unsorted
Sort order ascending or descending


43.JPG





GenerateRandomNumbersfunction.aia

Stuart Buchan

unread,
Nov 3, 2018, 7:21:31 AM11/3/18
to MIT App Inventor Forum
Nice one Italo!
Cheers, Stuart

Stuart Buchan

unread,
Nov 3, 2018, 12:09:23 PM11/3/18
to mitappinv...@googlegroups.com
Hi Italo

How did you create that procedure? I just want to sort and nothing else, so wanted to recreate your "Function" procedure without the other options.
I have managed to do it using existing blocks (see attached sort block image) but I'd love to be able to create Function blocks like yours, as I've used functions in other programming methods previously.

sort.jpg









Cheers, Stuart

Stuart Buchan

unread,
Nov 3, 2018, 12:51:04 PM11/3/18
to MIT App Inventor Forum
Hi Boban

I took your advice and added an additional seed in my block (see image below)


draw.jpg


Cheers, Stuart

Italo

unread,
Nov 3, 2018, 12:56:42 PM11/3/18
to MIT App Inventor Forum
It's a simple bubble sorting procedure.

Use this one with parameters instead. It will be easier to reuse in the same app or in other projects later.
Also specify "a" for ascending or "d" for descending.

Capture.PNG


SortingProcedure.aia
Reply all
Reply to author
Forward
0 new messages