Welcome to Dream.In.Code
Become a VB Expert!

Join 149,570 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,660 people online right now. Registration is fast and FREE... Join Now!




Generate random numbers

 
Reply to this topicStart new topic

Generate random numbers, help please

Genocide
21 Nov, 2007 - 02:16 PM
Post #1

New D.I.C Head
*

Joined: 21 Nov, 2007
Posts: 3


My Contributions
I'm making a CDKey Generator
how would i get it to Generate 13 random numbers?
Do i need a module for this? or no
User is offlineProfile CardPM
+Quote Post

oXiDe
RE: Generate Random Numbers
21 Nov, 2007 - 03:51 PM
Post #2

New D.I.C Head
*

Joined: 17 Nov, 2007
Posts: 37



Thanked: 1 times
My Contributions
ur supposed to post some code .. or they wont help u sad.gif
& why u need sc key gen when u already have a gg one :S
User is offlineProfile CardPM
+Quote Post

oXiDe
RE: Generate Random Numbers
21 Nov, 2007 - 04:06 PM
Post #3

New D.I.C Head
*

Joined: 17 Nov, 2007
Posts: 37



Thanked: 1 times
My Contributions
ill post my theory which i know is wrong, but atleast itl have code & someone smart will post the right way biggrin.gif

CODE
Private Sub Command1_Click()
    Text1.Text = Rnd(13) 'i believe rnd is short for random?
End Sub

User is offlineProfile CardPM
+Quote Post

Genocide
RE: Generate Random Numbers
21 Nov, 2007 - 04:07 PM
Post #4

New D.I.C Head
*

Joined: 21 Nov, 2007
Posts: 3


My Contributions
how do u get it to generate 13 random numbers?

CODE
Private Sub Form_Load()
Text1.Text = Rnd(1)
End Sub


it keeps generateing
0.7055475
sad.gif
i just want it to generate a 13 random number

and i tryed making a module
CODE

Public Sub RNumber(ParamArray saElements() As Variant)
    Dim i As Integer
    For i = LBound(saElements) To UBound(saElements) Step 2
        With Form1.rtbChat
            .SelStart = Rnd(1)
            .SelLength = 0
            .SelText = saElements(i + 1) & Left$(vbCrLf, -2 * CLng((i + 1) = UBound(saElements)))
            .SelStart = Rnd(1)
        End With
    Next i
End Sub


and it still genned
0.7055475 why is this?





This post has been edited by Genocide: 21 Nov, 2007 - 04:29 PM
User is offlineProfile CardPM
+Quote Post

oXiDe
RE: Generate Random Numbers
22 Nov, 2007 - 08:34 PM
Post #5

New D.I.C Head
*

Joined: 17 Nov, 2007
Posts: 37



Thanked: 1 times
My Contributions
i figured out some code that'd work, but the its not actually random, itl keep repeating itself every time the project is reopened.. i think this is because random is mathimatically impossible and it has to be based off of something that is constantly changing. but heres an almost random code :|

CODE
Private Sub Form_Load()

    txtText.Text = Int(Rnd(1) * 7) & Int(Rnd(1) * 7) & Int(Rnd(1) * 7) & Int(Rnd(1) * 7) & Int(Rnd(1) * 7) & Int(Rnd(1) * 7) & Int(Rnd(1) * 7) & Int(Rnd(1) * 7) & Int(Rnd(1) * 7) & Int(Rnd(1) * 7) & Int(Rnd(1) * 7) & Int(Rnd(1) * 7) & Int(Rnd(1) * 7)

End Sub

User is offlineProfile CardPM
+Quote Post

Ryan1
RE: Generate Random Numbers
23 Nov, 2007 - 09:30 AM
Post #6

New D.I.C Head
*

Joined: 29 Sep, 2007
Posts: 11


My Contributions
i dont know a whole lot but if you want whole numbers you could do something like this i used it in something before

CODE
Public Function Rand(ByVal Low As Long, _
                     ByVal High As Long) As Long
  Rand = Int((High - Low + 1) * Rnd) + Low
End Function


and then somewhere have something like A = Rand(1,20)

the first number is the lowest number possible the second is the highest it only does whole numbers though and make sure you put randomize in Form_load
User is offlineProfile CardPM
+Quote Post

kdkevin
RE: Generate Random Numbers
23 Nov, 2007 - 01:38 PM
Post #7

D.I.C Head
**

Joined: 8 May, 2007
Posts: 52


My Contributions
if it's vb6 then u should write this code:

text1.text=int(rnd*13)

here is a way to not get 0 as a number

text1.text=int(rnd*13)+1

hope this helps biggrin.gif

ooh srry i forgot do this instead:

randomize
text1.text=int(rnd*13)

or if you want no zeros then

randomize
text1.text=int(rnd*13)+1


hope this helps biggrin.gif
User is offlineProfile CardPM
+Quote Post

kdkevin
RE: Generate Random Numbers
23 Nov, 2007 - 01:45 PM
Post #8

D.I.C Head
**

Joined: 8 May, 2007
Posts: 52


My Contributions
ok here is wat u do(i'm good at vb6, i made 45 games using it)

to get random numbers just use this code:

randomize
text1.text=int(rnd*13)

if you dont want any zeros then do this

randomize
text1.text=int(rnd*13)+1

hope this helps biggrin.gif

not to be rude or anything but thoses guys were on the rite track but didnt really know it and the other guy gave you like 4 lines of code jus to randomize it and it doesnt randomize that good either. try mine, it works perfectly
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Generate Random Numbers
23 Nov, 2007 - 04:11 PM
Post #9

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 7,306



Thanked: 66 times
Dream Kudos: 500
Expert In: Everything

My Contributions
Topics merged. Please do not create duplicate topics.
User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 10:23PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month