cancel
Showing results for
Did you mean:
Helper III

## Draw random numbers

Hello everyone.
I have three text input boxes, where the boxes are defined as numbers. There are "min" numbers, "max" numbers and "quantity" numbers. When I press the random button, I create a table, with numbers from the text input boxes "min" and "max". Then I draw a random "quantity it is displayed in a gallery.

Then comes the question.
I want to press the random button once and the first random number should appear in a Label on the screen. Then I should be able to press the next button and the next number will appear in Label, and previous numbers will be shown in the gallery. Is this possible to achieve in a decent and simple way?
Attaches coding to the Random button. The formula is in the Norwegian setup of power apps. A comma becomes a semicolon and a semicolon becomes a double semicolon.

2 ACCEPTED SOLUTIONS

Accepted Solutions
Super User

OOOOOOOH OK Makes sense. Ok so Single number box

``Last(FirstN(Sort(numbersDraw,Random,SortOrder.Ascending), winningNumbers))``

mulitbox below it

``Concat(FirstN(Sort(numbersDraw,Random,SortOrder.Ascending), winningNumbers-1), Value, " ")``

then you can add a little to that all numbers box to show when all numbers have drawn say like

``````Switch(winningNumbers,
Value(TextInput3.Text),
Concat(FirstN(Sort(numbersDraw,Random,SortOrder.Ascending), winningNumbers), Value, " "),
Concat(FirstN(Sort(numbersDraw,Random,SortOrder.Ascending), winningNumbers-1), Value, " ")
)``````

and even set visible of the solo number box to

``````Switch(winningNumbers,
Value(TextInput3.Text), false, true)``````

adding in those last two will make it display one at a time and then move into the group as you continue until the end, at which point all numbers will show in the group box

_____________________________________________________________________________________
Like my answer? - Hit that Thumbs Up. Resolved the Issue? - Hit Accept as Solution.
This helps others find solutions to future issues!
Super User

watched your vide, looks lovely. Reason it just goes straight to the box below is the last part we added.

``````Switch(winningNumbers,
Value(TextInput3.Text), false, true)``````

change visible of the single text box from that, to true, and it will stay there 😉

_____________________________________________________________________________________
Like my answer? - Hit that Thumbs Up. Resolved the Issue? - Hit Accept as Solution.
This helps others find solutions to future issues!
15 REPLIES 15
Super User

Where I have 3 text inputs, set to numbers, named TextInput 1 2 3, in my buttons onselect I place

``````ClearCollect(numbersDraw,
ForAll(Sequence(Sum(TextInput2.Text+1-TextInput1.Text),TextInput1,1) As numberTurn, {Value:numberTurn.Value, Random:Rand()}))``````

In my label I place

``Concat(FirstN(Sort(numbersDraw,Random,SortOrder.Ascending), TextInput3.Text), Value, " ")``

_____________________________________________________________________________________
Like my answer? - Hit that Thumbs Up. Resolved the Issue? - Hit Accept as Solution.
This helps others find solutions to future issues!
Helper III

My formula works on the random button, but I want to add a new next button.

I want to press the random button once and the first random number should appear in a Label on the screen. Then I should be able to press the next button and the next number will appear in Label, and previous numbers will be shown in the gallery.

The ultimate would be that now that the last number has been drawn, a text will appear saying "No more moves"

Super User

If I understood correctly, you want to

1) Press Random once > then Next once (?) > then a text saying "No more moves"

2) Display the current value in a label, and the previous in a gallery

You can use a variable to capture the button presses.  Add something like this to the "OnSelect" for your Random and Next buttons:

``UpdateContext({varButtonPush: varButtonPush + 1})``

You can then reference this for your buttons in the DisplayMode property.  For example, for the "Random" button you can add:

``If(varButtonPush > 0, DisplayMode.Disabled)``

So you can disable your buttons as the user advances. For the "No More Moves", you can set the visible property to

``If(varButtonPush = 2,true,false)``

For the Gallery portion, you can capture the previous value into a collection, and then use that for your Gallery.   So if the current value is in your label, before you replace that with a new value, add this to the beginning of your formula:

``Collect(colPriorRandom,YourTextLabel.Text)``

You'll want to clear the collection at some point, but these are just a few ideas that may work for your use case

Super User

So, I would still make your random button different, as yours is far more complex than necessary and will make future edits harder if someone that isn't you has to work with this code one day.

To test, make a button with the onselect of

``````If(IsBlank(winningNumbers),
ClearCollect(numbersDraw,
ForAll(Sequence(Sum(TextInput2.Text+1-TextInput1.Text),TextInput1,1) As numberTurn, {Value:numberTurn.Value, Random:Rand()})));

Set(winningNumbers, If(IsBlank(winningNumbers),1, winningNumbers+1))``````

and set its displaymode to

``If(Not(winningNumbers=Value(TextInput3.Text)), DisplayMode.Edit, DisplayMode.Disabled)``

and it's text to

``If(Not(winningNumbers=Value(TextInput3.Text)), "Draw Number", "Draw Complete")``

then put a label in the screen with this text

``Concat(FirstN(Sort(numbersDraw,Random,SortOrder.Ascending), winningNumbers), Value, " ")``

this will draw one number at a time until the requested limit is reached, then chaneg your button from draw number to draw complete and make it unable to be pressed further. Can then reset it by placing this somewhere, if needed

``Set(winningNumbers,Blank())``

_____________________________________________________________________________________
Like my answer? - Hit that Thumbs Up. Resolved the Issue? - Hit Accept as Solution.
This helps others find solutions to future issues!
Helper III

Entered what you wrote and got this? Unable to press.

Super User

Check your display mode of the button and make.sure you changed the textbox3 reference to name of your own textbox where your draw count is located. And if it is correct then place a label somewhere and see what value is currently in winningNumbers (also check that all my formula textbox references where swapped when you put them.in your app so you dont end up with a reference throwing it off 🙂 )

_____________________________________________________________________________________
Like my answer? - Hit that Thumbs Up. Resolved the Issue? - Hit Accept as Solution.
This helps others find solutions to future issues!
Helper III

Typo on the text box. Thanks. This works well.
What if I want to show only one feature in a new text box, and that all are collected in the one I have now.

Super User

Do you mean you want a seperate text box for each number revealed by the draw?

_____________________________________________________________________________________
Like my answer? - Hit that Thumbs Up. Resolved the Issue? - Hit Accept as Solution.
This helps others find solutions to future issues!
Helper III

No, not separately. A textbox. The first number appears in and the next number appears in the same text box and the first goes into the text box that is there now. If this makes sense

Announcements

#### Tuesday Tip | How to Get Community Support

It's time for another Tuesday Tip, your weekly connection with the most insightful tips and tricks that empower both newcomers and veterans in the Power Platform Community! Every Tuesday, we bring you a curated selection of the finest advice, distilled from the resources and tools in the Community. Whether you’re a seasoned member or just getting started, Tuesday Tips are the perfect compass guiding you across the dynamic landscape of the Power Platform Community.       This Week: All About Community Support Whether you're a seasoned community veteran or just getting started, you may need a bit of help from time to time! If you need to share feedback with the Community Engagement team about the community or are looking for ways we can assist you with user groups, events, or something else, Community Support is the place to start.   Community Support is part of every one of our communities, accessible to all our community members.   Within each community's Community Support page, you'll find three distinct areas, each with a different focus to help you when you need support from us most. Power Apps: https://powerusers.microsoft.com/t5/Community-Support/ct-p/pa_community_support Power Automate: https://powerusers.microsoft.com/t5/Community-Support/ct-p/mpa_community_support Power Pages: https://powerusers.microsoft.com/t5/Community-Support/ct-p/mpp_community_support Copilot Studio: https://powerusers.microsoft.com/t5/Community-Support/ct-p/pva_community-support   Community Support Form If you need more assistance, you can reach out to the Community Team via the Community support form. Choose the type of support you require and fill in the form accordingly. We will respond to you promptly.    Thank you for being an active part of our community. Your contributions make a difference!   Best Regards, The Community Management Team

#### Hear what's next for the Power Up Program

Hear from Principal Program Manager, Dimpi Gandhi, to discover the latest enhancements to the Microsoft #PowerUpProgram, including a new accelerated video-based curriculum crafted with the expertise of Microsoft MVPs, Rory Neary and Charlie Phipps-Bennett. If you’d like to hear what’s coming next, click the link below to sign up today! https://aka.ms/PowerUp