Tracker
 ASP PHP JavaScripts MySQL MS Access MSSQL VISUAL BASIC Subjects/Titles Post Text/Content
HOME    TRACKER    Visual Basic

# Excluding Numbers From Random Generating

## Good day!I develop a random number generator. I need to generate, for example, numbers from 1 to 90. How can I exclude from generating such numbers, like, for example, 89,76,2 and 7. How can I do that? What I was doing is adding each new generated number to a collection of restricted numbers, so if such a number appears, it generates another one and so on until all numbers are generated. But the presented algorithm is not the optimal one I think. Any ideas on how to implement the functionality?Thanks!

Generating Random Numbers
I was wondering if anyone knew how to create a random number generater that would symbolize a deck of cards. I alread know how to generate the 52 numbers nut i don't know how to make the program use each number only once.

Generating A Set Of Random Numbers
i would like to know how to generate random numbers between two set numbers. For example, 0-999.

Any ideas?

Thanks,

Sam

Generating Random Numbers In VB6
For a project I have currently done, I have designed a database that contains a table, which contains the field "NHS Number". People in the UK would know that this is a unique ten digit number.

I am in the process of adding "people" into the database for testing purposes.

In real life, different people would have totally different NHS Numbers, so using AutoNumber is totally out of the question. So I have to have a random number...

I have currently made a random integer generator to solve this problem... or so I thought

Using the following code:

vb Code:
Private Sub Command1_Click()    Dim dblRand As Double    Dim strRand As String    dblRand = Int(Rnd * 10000000000#)    Text1.Text = dblRand    Clipboard.Clear    strRand = dblRand    Clipboard.SetText strRandEnd Sub

Using the
Code:
Int()
command doesn't acutally generate a random number each time for me. While I'm running the program, it generates random numbers, fair enough. When I start the program again, it generates the same random numbers it did before

Is there something I've done wrong? Is there another way to randomise numbers?

Thanks

Generating Random Numbers
I am fairly new to vb. But I dont know how to go about this problem. What I need is to Generate Random Numbers between 0 and 1. Numbers cant be more than 3 decimal places (.000).

I need help on this ASAP. So if anyone can shed some light on this, it would be great.

If you can provide code it would be even better.

Generating Random Numbers
In the Program I am Writing I need to have the ability to generate random numbers... Mainly 1-100 right now I used this

per1.Text = Int(Rnd * 100)

But it does not generate a very random number beig each time i run the program it runs the same numbers...
ButI also need to know how to generate random numbers for other TYPES of dice.. Such as a D3 D6 D10 and d20 But I do not even know where to start generating these? if anyone can give me a step in the right direction........

TIA
Rogan

Generating Random Numbers
How does one go about generating a random number in VB? I'm interested in knowing how to generate one in two scenarios:

Generate random # between 1 and 298
Generate random # between 0 and infinity

Generating Non-Linear Random Numbers
I need to create random data but not on a linear scale. For example, I want random data to show how many TVs are in a household. For this example the range I am working on is 1 to 11. I could use:

randomValue = Int(Rnd * 11) + 1

But I want the random results to be based on a percentage. For this example (see below), when I create my data, I want 4% of housholds to have 1 TV, 8% to have 2 TVs, 12% have 3% and so on...

14%
28%
312%
420%
523%
613%
711%
83%
93%
102%
111%

How can I generate this? There is probably already an example here for this, but I do not know what it is called to be able to search for it.

Thank you.

Generating Random Numbers For The Lottery
Someone was asking recently abount generating random numbers for the lottery. Here's the code...

I've commented it as best I can, but if you've any questions, let me know...
_____________________________________________________________
Option Explicit

'1. Select 6 random numbers from 42
'2. Sort them
'3. if any numbers are the same, select a random number to replace them
'4. repeat steps 2 & 3 until all numbers are different

'When debugging this code, set ArraySize to a large number (say 25), so
'you'll get lots of duplicates and so testing will be easier.

Sub Main()

Dim i As Integer
Dim NumberString As String
Dim temp1 As Integer
Dim Sorted As Boolean

Const ArraySize = 6 'Choose this amount of numbers from TotalNumbers...
Const TotalNumbers = 42 'Choose from these numbers...

Dim arrRandom(1 To ArraySize) As Integer

Randomize
For i = 1 To ArraySize
arrRandom(i) = Int(Rnd * TotalNumbers) + 1
Next i

Sorted = False

'The nested while loop is not wholly necessary for the program to work.
'You can take it out. The reason I've included it is for efficiency -
'when the nested while finishes, the numbers will be sorted, ready for
'comparison. If the nested while loop were excluded, the test for
'duplicates would not be comparing values from a sorted array and would
'therefore be pointless.
'But if you can come up with a nicer way of doing it...
While Sorted = False

'Sort the array in ascending order
'The logic here assumes that if one swap is made, the array is not
'sorted, so it goes back to the top and sorts again. When no swaps
'are made, the Sorted variable will be true and the loop will end.
While Sorted = False
Sorted = True
For i = 1 To UBound(arrRandom) - 1
If arrRandom(i) > arrRandom(i + 1) Then
temp1 = arrRandom(i)
arrRandom(i) = arrRandom(i + 1)
arrRandom(i + 1) = temp1
Sorted = False
End If
Next i
Wend

'Check for duplicates - if there are any, replace them with another
'random number. When the for loop finishes, we need to sort again,
'at which point we go back to the top of the while loop.
For i = 1 To UBound(arrRandom) - 1
If arrRandom(i) = arrRandom(i + 1) Then
arrRandom(i) = Int(Rnd * 42) + 1
Sorted = False
End If
Next i

Wend

'Output the chosen numbers via a message box
NumberString = arrRandom(1)
For i = 2 To UBound(arrRandom)
NumberString = NumberString & ", " & arrRandom(i)
Next i
MsgBox NumberString

End Sub

Generating Random 4 Letters And/or Numbers
Hello,

How can I make my program generate a random combination of letters and numbers and display them in a textbox?

Generating Sequence Of Random Numbers
Hi everybody,
I want to generate sequence of numbers without repetition.
How can I do this?

Regards,
Saeed

Generating Random Numbers, Whole Numbers Only
hello all!

I used this code to generate random numbers in VB:
Code:lRndNum = (65000 * Rnd)

where I wanted to produce a bunch of random numbers from 0 to 65000.
My problem is, I want to discard the decimal points in the generated random result.

I only want to have random numbers, whole numbers, that is, without the messy decimal point.

I hope you'll hear me out. Thanks!

Generating Random Numbers, But Not Repeating Any, Is There An Easy Way To Do This?
How can I generate random numbers but not repeat any that have already been generated. Is there an easy way to do this at all?
Thanks!
Eric

Problem In Generating Distinct Random Numbers
i am using this below code to generate random numbers
g=cint(rnd*10)+1
msgbox g
but some time repeating random numbers occurs like when i click
command button msgbox giving 6 and when i click command button IInd time msgbox giving 4 and for IIIrd time it is once again
giving 6 this is what i want to prevent, how can i prevent this.

Array Help (generating Unique Random Numbers)
ok the problem i have is i want 6 random numbers to be generated inside 6 text boxes i then want the 6 boxes to be checked so they dont have

Code:

spent = spent + "1"
lblSpent = ("£" & spent)

For x = 0 To 10

ball(x) = Int(Rnd() * 10) + 1

Next x

For x = 0 To 5

lblResult(x) = ball(x)
Next x

lstWinningNums.AddItem (lblResult(0) & " " & lblResult(1) & " " & lblResult(2) & " " & lblResult(3) & " " & lblResult(4) & " " & lblResult(5))

that happily givs me mynumbers, so how do i use an array to check each box for the same numbers then get it to genrate a new number

Excluding Everything But Numbers
I've got some code to pull values from a txtbox and use it in a calculation. Problem is I can't stop users from putting in alpha characters and throwing exceptions. The calculations happen automatically triggered by txtbox change. Code follows:

Private Sub txtRate_Change()

Call mortPayCalc

End Sub

Private Sub mortPayCalc()

Dim sglPrice, sglRate, sglDuration, sglMortgage As Single

If (txtPrice <> "") And (txtRate <> "") Then
sglPrice = txtPrice
sglRate = txtRate / 100
If (cboDuration = "10") Or (cboDuration = "15") Or (cboDuration = "20") Or _
(cboDuration = "30") And (sglPrice > 0) And (sglRate > 0) Then
sglDuration = cboDuration
sglMortgage = sglPrice / ((1 - (1 / ((1 + sglRate) ^ sglDuration))) / sglRate)
txtMortgage = Round(sglMortgage, 2)
End If
End If

End Sub

Excluding A Random Number
I am generating random numbers from using the code:

i = Int(Rnd() * 6) + 1

This is fine, but what do i do if i want to exclude the number (e.g.) 2?

thanks

Random Numbers-is It Possible To Generate Random Numbers With A Algorithum?
The rnd function in vb generated pseudo-random numbers. That means if you use these numbers as a key for some type of encryption it would make it fairly easy to break(if you knwo how) because you can predict what numbers will be generated by the rnd function.

I'm trying to design a method that might involve a couple of diffrent algorithums to genertae random numbers.
One of my idea's was to monitor network traffic for numbers, error messages, etc...
At the moment I have absolutely know idea howto monitor the arrival of packets or error messages, so if you knwo how please respond!!!

The Random Function Gets The Same Random Numbers Every Time I Start The Program
I'm making a Poker program

The code is like:
Command1_click sub()
Card1.caption = int(rnd()*53) +1
Card2.caption = int(rnd()*53) +1
Card3.caption = int(rnd()*53) +1
Card4.caption = int(rnd()*53) +1
Card5.caption = int(rnd()*53) +1
End sub
( I use much more codes of course)

When I click the command1 button, I get the numbers random, but I get the same random numbers in the same order every time I start the game.
Example.

I start the game:
I click command1: card1= 9, card2= 18, card3= 42, card4= 23, card5= 4
I click command1 again: card1= 7, card2= 51, card3= 13, card4= 29, card5= 14
and so on, random every time I click...

I start the game again, another time:
I click command1: card1= 9, card2= 18, card3= 42, card4= 23, card5= 4
I click command1 again: card1= 7, card2= 51, card3= 13, card4= 29, card5= 14
and so on, random every time I click. But I get the same numbers, In the same order.

I hope I've explained my problem well.

Random Generating
i am creating a program that i want to simulate a bit test with. so if i click on label.caption i want label14.caption to to go from the caption "bite" to a 5 sec delay during which it will display "bite in progress" and after the time period of 5 sec i want label14.caption to select at random a fault from a list i specify.

Generating A Random
Hello, i have a playlist editor for an MP3 player and would like to have a random song play function. I know how it would work but not sure about the code required to generate the random number values. I would need code to fetch how many entries there are in the listbox, then some code the generate a randon listindex number, any ideas?

Generating DIFFERENT Numbers
I have a prog wich generates some random numbers.
How do i make sure that all my random generated numbers are different numbers?

Code:
Private Sub Command1_Click()
Dim i As Single
Dim a(0 To 6) As Double
Dim RandomNumber As Double

For i = 0 To 6
RandomNumber = Int(Rnd() * 42) + 1
a(i) = RandomNumber
Label(i).Caption = a(i)
Next i
End Sub

Generating Numbers
I was wondering what the best way to generate a list of numbers in the range of 0000 - 5000 would be? I tried looping, but I cannot loop through more than one 0 at a time.

For example, if I do this:

Code:
Dim NumLoop As Integer
NumLoop = 0000
Visual Basic will reset "0000" to just a single 0. So, how can I generate numbers from 0000 - 5000 easily?

Generating Numbers!!
Hi!

I am trying to generate some numbers as follows:

From: 00000000001
To: 99999999999

Well the problem is when i try to do it using a loop or something as soon as i press enter or space after typing the number 00000000001 VB converts it to 1 automatically.

And the other problem is that when i type in a big number like this VB automatically adds a '#' sign after the number! i don't know what it means but then i am unable to generate the numbers.

Any solutions ?

Thanks!

Generating Possible Numbers
Ok what i want to do is here is a picture those 6 boxes the user inputs numbers say 1-50 in each box then when they click generate possible numbers meaning combinations label on the right tells them how many and the big textbox multilined tells them all the possible numbers dashed can yall help me out?<p>

Generating Numbers..
Hmm, not sure how to put this really.. I wanna know if it's possible to generate a WHOLE list of the possible combinations you can make using 0-9.. An I want it to remove doubles if there are any.. Is there ANYWAY at all this coule be done?

Generating Numbers
OK, I have 9 labels, in which I want to display 9 numbers,
from 1-9.

Now, I need to display each combination of possible numbers, in a methodical way, using a timer, where each time it fires, a new set of numbers appears.

Any ideas?

Thanks,
Jez

Generating A Random Dungeon Map...
Programming slashers are pretty fun. Playing them are fun too. The one thing I have found that makes the games old quickly is "static maps".

I've done a few games with great "map editors", but after a while, creating "new maps" get's to be a pain and, besides, if you create the map yourself... where's the adventure in that?

About the most famous of ALL games in which has random map generators is Diablo 1 & 2. I guess that's why those games stay popular for so many years... the maps are always different for each game.

In doing this, I have discovered it's no easy task to "do a good map everytime".

Plain "Map editors" are easy and aren't much of a challenge. I'm looking for something to make a game engine that will keep interest.

I've done a couple of generators, but the results are no where near satisfying.

I am wondering if there is anyone here who has successfully coded a Random Map Generator?

I'm NOT looking for code... What I am looking for is "approach", or flow of your code.

I'm starting with simple maps. 2D Square Dungeon maps. Rooms and Hallways and Doors.

My approach is starting top left, doing 1 square at a time. Do some logic on the surrounding squares, make a decision on what to make that square, move on to the next.

The problem is there isn't much structure to the map.

How would you do it? Generate Hallways for the Map, then fill in the spaces with Room, then Doors?
Or, Generate Rooms throughout the map, then fill in with hallways?
...etc.

Just looking for some Code "FLOW" ideas.

Thanks!

Generating A Random Number
Hi,

How to create a random number between 30000 and 40000 ?

Generating A Random Number Between 1 And 10
What code can I use to generate a random number between 1 and 10. This is how it is gonna work... I have 10 quetions for my users:

Question1
Question2
Question3
Question4
Question5
Question6
Question7
Question8
Question9
Question10

and I need to generate 5 random numbers between 1 and 10. These random numbers will decide which 5 questions my program will ask them. so if one of the random numbers is 3 it will ask them question 3. Any ideas how I can do this?

Generating 7 DIFFERENT Random Integers
I need to generate 7 integers between 1 and 7 that are all different. Thanks.

By the way... This is the code I have so far (will only genertae the numbers, not make sure they are different)

Code:

Randomize()
z = Int(Rnd() * 7) + 1
y = Int(Rnd() * 7) + 1
x = Int(Rnd() * 7) + 1
w = Int(Rnd() * 7) + 1
v = Int(Rnd() * 7) + 1
u = Int(Rnd() * 7) + 1
t = Int(Rnd() * 7) + 1

[HELP] Generating Random Filenames
Hello there. I need some help generating random filenames.

I have tried:

Code:
Dim 1 As String
Dim 2 As String
dim 3 As String
3 = randomnumber
2 = ".ini"
1 = App.Path & "" & "3" & Extension
Print #1, "#Account DO-NOT-CHANGE-ANYTHING-HERE"
Close #1

Something like that, but the file wont save, and gives me an error. Can someone please help?

Generating Random Pictures
Ok, So i have a big picture box on a form which will work as the battle background for a turn based game I am making. I want it to load one of the random backdrop pictures i have on form load.

So heres the code I have made so far, but it does not seem to work. This is important because I dont want to have the same background on every fight and im not using multi forms just to battle with different backdrops.

Someone help

Code:
Const MAX_BACKGROUND As Integer = 10
Dim bgArray(MAX_BACKGROUND - 1) As String

InitBackground
SelectBackground
'This just displays a name they entered
nameShow.Caption = ReadINI("config", "CharName", App.Path & "config.ini")
End Sub

Private Sub InitBackground()
bgArray(0) = "backdrop1.jpg"
bgArray(1) = "backdrop2.jpg"
bgArray(2) = "backdrop3.jpg"
bgArray(3) = "backdrop3.jpg"
bgArray(4) = "backdrop3.jpg"
bgArray(5) = "backdrop3.jpg"
bgArray(6) = "backdrop3.jpg"
bgArray(7) = "backdrop3.jpg"
bgArray(8) = "backdrop3.jpg"
bgArray(9) = "backdrop3.jpg"
End Sub

Private Sub SelectBackground()
Dim RandomNumber As Integer
RandomNumber = Random(0, MAX_BACKGROUND)

Dim curPath As String
curPath = "graphics"

End Sub

Function Random(Lowerbound As Long, Upperbound As Long)
Randomize
Random = Int(Rnd * Upperbound) + Lowerbound
End Function

Help Generating A Random Number [vb 6]
hello

im looking for the old way of generating a random number, linking it to a variable. I remember it being something quite simple but i cant remember the exact code for it

thanks

Generating Random Letters In Vb 6.0
Hi all

Sorry should have explained this in more detail, here's what I want to do.
I have one form with 5 text boxes on it and need to generate random letters between A-F and random Numbers between 0-9

For Example: Text box 1 A0, Text 2 B7 Text 3 F9 Text 4 C6 Text 5 E8

So when the user clicks the command button, the program will generate random letters and numbers in each of the text boxes.

Could anyone maybe just point me in the direction with a couple of lines of code to perform this task.

Thanks for any help in advance

Cheers,
Steptoe

Generating A Random Number?
Is there anyway to make VB generate a random number.
eg.
Integer = Random(0,200)
so it would pick a number between 0 and 200

Generating Random Letters
Okay, here's a couple questions that should be pretty easy to answer. First, how can I generate random letters? And since I haven't really used loops before in the stuff I've made, how can I make a loop so that the program continuously just generates these random letters over and over? Or perhaps a timer would be involved? These should be simple but I'm just not sure how to do it right.

Generating Random Strings?
I want to make a simple little app where you click a command button and it puts random text into a text box. So how can i set some text as a string and randomize it upon the command button click?

E.G:

I have these strings

This is a random text string 1
And so is this but random 2
I am also a random text string 3
I might be lucky and randomly picked to be put in the text box

If you get what i mean, now on the command button click one of the above strings are selected.

THANKS!

Generating Random Number
Hi everybody,

Anyone knows how to generating Random Integer Number beetwen 1 to 1000 ?

OK, I have an array named

strArray()

it holds 50 different strings created dynamically.

How then can I tell VB to resort the array in a random order?

Thanks

Generating Random Number....
I need a generate a random 13 digit number with no 0's can anyone tell me how to do this?...

Generating A Random Number
Hi, How do I generate a random 8 digit number?

Generating A Random Number
Hi, How do I generate a random 8 digit number?

Generating Random Number
Anyone know any code to make VB generate a random number between 1-100, 1-20, 1-10, and 1-6? For anyone who plays AD&D, i'm making a Magical Item Generating program.

Generating A Random Number In SQL
Cheers Joe & Bruce, I'll try creating a recordset.

Generating Random Times
Hi

Anybody got a good way of generating a random time, compare the result against another time and then act on it??

Cheers

Generating Random Number
Some one please guide me for generating the random number

the question is

Write a VB program to generate random numbers n where n is = 5, 10, 15 and 20

the user should select value of N from a combo box
and respective n random number should be generated.

Generating Numbers Automatically
I have an ItemNo and I used a label to display it. What I want to happen is, whenever I create a new Item Information (a form which contains the ItemNo label and other fields w/c pertains to an item), an autogenerated number is displayed on the label and it the number increments whenever new Items are added.

How do I do this? Thanks a lot guys for the help!

Random Number Generating Question??
Hullo again...

I've a question for the guru's (or anyone who can answer it)

I'm trying to create some random numbers for an array of objects.
I can't seem to figure out how to create random numbers for all of my objects where no two are alike.

Example: I have 10 objects, A B C D E ....etc... I need to be able to create a random number between 1 - 10 for each object not using the same number twice.

A = needs to be a random number
B = needs to be a random number and not = to A
C = needs to be a random number and not = to A and B
.....etc....

Do I need to use loop statements?

An example would be GOLD!

Thanks!

Generating A Random Binary Number
What would be the easiest way to generate a random binary number in VB?