Jump to content

How to make a number generator?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
13 replies to this topic

#1
wazofski

wazofski

    Programmer

  • Members
  • PipPipPipPip
  • 126 posts
How do I make a number Generator? Can somebody explain me? (with the code)

#2
kresh7

kresh7

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 661 posts
its pretty easy ok heres what you need a textbox and a command button

insert this code on the command button

Quote

text1.text = Rnd * 99999999999#

thats all if you use a timer its more intereseting cuz you see how the numbers generat randomly :D

#3
slovig

slovig

    Newbie

  • Members
  • Pip
  • 5 posts

Quote

Dim random as New Random
dim num as integer
num=random.next(start Value, End value***)
me.xoutputlabel.text=num

***You must enter one more than what you want. So if you want a number from 1 to 100, the code would be

Quote

num=random.next(1,101)


#4
TcM

TcM

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 11,147 posts
Great help guys. +rep given to you both.

I guess that wazofski can figure things out thanks to your help.

#5
wazofski

wazofski

    Programmer

  • Members
  • PipPipPipPip
  • 126 posts
mm thx

#6
jiros

jiros

    Newbie

  • Members
  • Pip
  • 1 posts
Thanks, i was wondering about that too. ^^

#7
RagedSparrow

RagedSparrow

    Newbie

  • Members
  • PipPip
  • 10 posts
I went a step further with this. If you want to have a user defined parameter for the generator to work within, then your code can look like this.

Dim random As New Random
        Dim num As Integer
        'declare the the user input variables
        Dim start As Integer
        Dim finish As Integer
        start = Val(Me.value1Txt.Text)
        finish = Val(Me.value2Txt.Text) + 1
        'randomly generat a number withing the user defined parameters
        num = random.Next(start, finish)
        'display output
        Me.resultLbl.Text = num

I've always love tweaking code some. Don't mind the comments, i do it so i don't lose myself (as I have ADD and find that it happens a lot). Hope it helps you further your project a little more, or helps someone with maybe that question.

#8
TcM

TcM

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 11,147 posts
Hmm my VB shows me an error in this line

Dim random As New Random

It does not accept As New Random (There is no Random in my list)

#9
RagedSparrow

RagedSparrow

    Newbie

  • Members
  • PipPip
  • 10 posts
I'm not exactly sure why it is doing that for you, it seems to be working fine for me. Are you having it run the code inside the event handler, or are you running the code at the start of the program?

#10
TcM

TcM

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 11,147 posts
What do you mean? I made that code in the form_load

#11
RagedSparrow

RagedSparrow

    Newbie

  • Members
  • PipPip
  • 10 posts
It works for me if the code is run inside an event handler such as the clicking of a button, i'm not sure exactly why yours isn't working, i will run some tests when i get home later today and do some troubleshooting and see if maybe I can come up with a solution.

#12
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
Try System.Random instead. Maybe you need to reference a library or something.
P.S. Can I have some reputation points, too? Pleeeease? I never get any (sob, sob).
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums