Click here to Skip to main content
15,907,281 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
im trying to make an application using vb.net
an app that can raffle 1 to n. but not just raffle it, it'll show many random numbers first before showing the last final random number.
is it possible to code it?
i tried many codes from the internet but it most codes show the number immediately after a button click

i tried also using the timer so that every time the timer ticks the number changes but its not random, it will pick from an array. and do it from 1 to n . not randomly.

did any body tried this kind of codes?

What I have tried:

Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Randomize()
        TextBox1.Text = Int(Rnd() * 75)
     





    End Sub
End Class
Posted
Updated 24-Jun-21 23:27pm

The simplest way is to actually emulate the way a tombola / lottery draw machine works.
It has a container which holds all the numbers in the competition, and rotates un=til one drops out.

So create a List(Of Integer) and fill it with all the numbers you can have. If there are 10 "balls" in play, put the numbers 1 to 10 in there.
Then generate a random number in the collection - use the Random class to select a number between 0 and the number of items in the List minus one, then use that as an index into teh List. That value will be your "winner".
Then in your timer, you generate another random number oto access an item from the List, get the value, and remove it from what is left in the collection.
If that matches your winner, it's over. If not, let the Timer tick again.

It's not difficult, not really - it's the way you would do it manually!
If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 
Comments
Beginner213456 27-Jun-21 21:19pm    
i opened the link you sent me it says all codes are c# , are the codes from vb.net and C# the same.

or can you please provide some of the codes i can learn from to?
OriginalGriff 28-Jun-21 0:33am    
If you read what it says:
"All the code here is in C# - but it's all pretty simple stuff, and the process is the same in any language. Just "bleep" over the brackets and semicolons if you don't understand them!"

So try that: just "bleep" over the curly brackets and assume they are VB End statements.
If you still can't cope, then try here: http://www.developerfusion.com/tools/convert/csharp-to-vb/
I am not sure what your problem is but generating a set of random numbers is fairly simple:
VB
Randomize()
Dim number as Integer
For i As Integer = 1 to 10 ' generate 10 random numbers
    number = Int(Rnd() * 75)
    Console.WriteLine($"number: {number}")
Next
 
Share this answer
 
Comments
Maciej Los 25-Jun-21 5:56am    
Richard, seem that OP want to create a lottery system, where there's predefined number of numbers to randomize. He want to get a single number on every button click.
Richard MacCutchan 25-Jun-21 6:02am    
Quote: it'll show many random numbers first before showing the last final random number.
Beginner213456 27-Jun-21 21:12pm    
i tried the code you gave me and the "&" says character is not valid.
anything i can try?
Richard MacCutchan 28-Jun-21 3:36am    
It is not an '&', it is a '$' (dollar sign), which marks the string as interpolated (see $ - string interpolation - C# reference | Microsoft Docs[^]).

As to saving data in a TextBox, you just need to set or add the strings to the Text property of the box. The documentation will show you examples.
Beginner213456 27-Jun-21 21:16pm    
also, how to save the randomized number in a textbox after clicking a button.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900