Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




[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?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Creating Random Filenames
hi,
i would like to programm an algorythm to create uniqe random filenames, such as "iufcholssjlvfbslvpsvwsdvsh.avi"! how can this be done?

thx & greets

natarius

Random Array Of Filenames
using this code i get all the file names in the folder "img" and i am listing it into a list box

Code:
Dim s As String
s = Dir$("C:img")
While Len(s)
s = Dir$
Wend
now i need to put all the file names into an array and then make it random order then display on a list box

can anyone help me pls.

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 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 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 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

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


Private Sub Form_Load()

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"
BattleScreenPicture.Picture = LoadPicture(curPath + bgArray(RandomNumber))

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 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 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 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.

Thanks to all that reply.

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 ?

please tell me .....

Generating Random Arrays!!! HElp Please
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 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 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.

thanx in advance

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

Thanks for your time!

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.

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?

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

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!

Function For Generating A String Of Random A's And Z's
fior e.g., if I do

RandomString(8)

It will return me a string of random characters of length 8, any ideas how i can do this?

Random Number Generating Problem
I wrote the following function to generate a random integer number for me. The 2 arguments are the minimum and the maximum number the result must in between of.


VB Code:
Private Function RndInt(intMaximum As Integer, Optional intMinimum As Integer = 0) As Integer   'maakt een random willekeurig nummer aan'   'Pre: intMax >= 0'   'Post: RndInt is een random nummer waarvoor geldt: intMinimum <= RndInt <= intMaximum'      Randomize (Timer) 'Zorgt dat het seedgetal uniek is voor het huidige moment'   RndInt = intMinimum + Int(Rnd * intMaximum) 'Bereken het random getal'End Function


problem is however, it seems to generate more negative numbers then positive numbers. How is this possible?
(btw: changing this: Int(Rnd * intMaximum) to this: Int(Rnd * 2 * intMaximum) seems to solve the problem for the most part)

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?

Random Number Generating Object
I need an object that will generate random numbers within a user specified range, the user will be able to choose whether or not to require that a unique number will be chosen, the Object will display the current random number on a form, Along with the previously selected number..... Help.... I know how the Randomize stuff works... it's just the Object that has me stumped... Thanks!

Generating A Random Plus, Minus, Devide, Etc...
Ok, I am kinda creating this "math" program to solve a game called krypto but I have a problem I need a code that can generate random : + , -, *,/, so that i can put them between variebles : A * B + C * D - E = G and have it generate the functions at random and place them between the variebles. Some help? Thanks

PS: I don't care if its an OCX, win API, or just plain old VB code as long as it does what I want it to!

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 Records From The Database
Hi
I want to genrate Random Record from my access database
for example my database name is rand.mdb table name is PC field name
is empname.

in my form i have one text box txtemp
under command Butoon what code i shuuld write which get the random
record from table and display in the text box.
Regards
Moqeet

Generating Random Coordinates To Put In An Array
Hi~

I want to fill an array (1 to 10, 1 to 10) with random numbers (ranging from 0 to 5400). Then use that array as a way of getting coordinates for an array of 10 command buttons. Each time the form is loaded, I would like the coordinates for all 10 to be different...

Help?

THANKS!

Problem Generating A Random Number...
Hi,

On my form there is a button and a text box. When I click the button it generates a random number between 1 and 100. But if I hit stop and then play to reload the form and press the button again, it generates exactly the same numbers each time.

How can I make them different each time.

Here is the current code:

Private Sub Command1_Click()
NumberGen = (Int(Rnd * 100) + 1)
Label1.Caption = NumberGen
End Sub

Any Info thanks

Mark

Generating Random Text Output
I need to know how I can generate a random text response.
I am developing a program that will generate RANDOM text responses from a set list.
These responses will be triggered by a command button.
Do I need to create an access database where the responses can be drawn from?
How do I code this into my program?
Thanks

[easy] Generating A Random String From An Array
Here's a very simple question with a probably very simple answer..

I made a form with a CommandButton1 and a TextBox1 in VB 6.3. This is what I want to make happen: click the CommandButton1 -> make appear a string in TextBox1, randomly chosen from an array consisting of these three words 'apple', 'pear', 'banana'. This should be completely random, eg. clicking the button 5 times in a row may give an output sequence like this: banana - pear - banana - apple - apple.

That's really all the code should do From there I can work on my project myself.

(there doesn't seem to exist many good free VB tutorials online, and the book I got from the library down town isn't of much use either..)

Who can help me out? Should be a quickie!

Generating Random Number Based On A Machine
Hi, i need a routine to generate a random number based on a machine serial.

The idea is to get and automatic 6 digit number, it numbers change from 1 machine to another.


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

Copyright © 2005-08 www.BigResource.com, All rights reserved