473,706 Members | 2,408 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

random numbers and letters

hey gang.

I have a code to create a random string of letters. The number of them can
be whatever I desire.

what i would like to do, is have it both letters and integers. how would i
modify this code to allow that.

'***** make random password ******
Sub StrRandomize(st rSeed)
Dim i, nSeed
nSeed = CLng(0)
For i = 1 To Len(strSeed)
nSeed = nSeed Xor ((256 * ((i - 1) Mod 4) * AscB(Mid(strSee d, i, 1))))
Next

Randomize nSeed
End Sub
'----------
Function GeneratePasswor d(nLength)
Dim i, bMadeConsonant, c, nRnd

Const strDoubleConson ants = "bdfglmnpst "
Const strConsonants = "bcdfghklmnpqrs tv"
Const strVocal = "aeiou"
GeneratePasswor d = ""
bMadeConsonant = False
For i = 0 To nLength

nRnd = Rnd

If GeneratePasswor d <"" AND _
(bMadeConsonant <True) AND (nRnd < 0.15) Then

c = Mid(strDoubleCo nsonants, Len(strDoubleCo nsonants) * Rnd + 1, 1)
c = c & c
i = i + 1
bMadeConsonant = True
Else

If (bMadeConsonant <True) And (nRnd < 0.95) Then

c = Mid(strConsonan ts, Len(strConsonan ts) * Rnd + 1, 1)
bMadeConsonant = True

Else

c = Mid(strVocal, Len(strVocal) * Rnd + 1, 1)
bMadeConsonant = False
End If
End If
GeneratePasswor d = GeneratePasswor d & c
Next
If Len(GeneratePas sword nLength) Then
GeneratePasswor d = Left(GeneratePa ssword, nLength)
End If
End Function
'----------
StrRandomize CStr(Now) & CStr(Rnd)
var_var = GeneratePasswor d(6)
'************** *************** *********

this gives me 6 letters at random.
for example utjand

i would like it to give say 3 letters and 3 numbers. is this possible with
the code i have?

TIA
Bam
Mar 31 '07 #1
1 3142
scratch that. one of these days I will learn to just think!!

just added 1234567890 in the Const strConsonants = "bcdfghklmnpqrs tv"
line, all is well
thanks
"Jeff" <ba*@gig-gamers.comwrote in message
news:46******** *************** @roadrunner.com ...
hey gang.

I have a code to create a random string of letters. The number of them can
be whatever I desire.

what i would like to do, is have it both letters and integers. how would i
modify this code to allow that.

'***** make random password ******
Sub StrRandomize(st rSeed)
Dim i, nSeed
nSeed = CLng(0)
For i = 1 To Len(strSeed)
nSeed = nSeed Xor ((256 * ((i - 1) Mod 4) * AscB(Mid(strSee d, i, 1))))
Next

Randomize nSeed
End Sub
'----------
Function GeneratePasswor d(nLength)
Dim i, bMadeConsonant, c, nRnd

Const strDoubleConson ants = "bdfglmnpst "
Const strConsonants = "bcdfghklmnpqrs tv"
Const strVocal = "aeiou"
GeneratePasswor d = ""
bMadeConsonant = False
For i = 0 To nLength

nRnd = Rnd

If GeneratePasswor d <"" AND _
(bMadeConsonant <True) AND (nRnd < 0.15) Then

c = Mid(strDoubleCo nsonants, Len(strDoubleCo nsonants) * Rnd + 1, 1)
c = c & c
i = i + 1
bMadeConsonant = True
Else

If (bMadeConsonant <True) And (nRnd < 0.95) Then

c = Mid(strConsonan ts, Len(strConsonan ts) * Rnd + 1, 1)
bMadeConsonant = True

Else

c = Mid(strVocal, Len(strVocal) * Rnd + 1, 1)
bMadeConsonant = False
End If
End If
GeneratePasswor d = GeneratePasswor d & c
Next
If Len(GeneratePas sword nLength) Then
GeneratePasswor d = Left(GeneratePa ssword, nLength)
End If
End Function
'----------
StrRandomize CStr(Now) & CStr(Rnd)
var_var = GeneratePasswor d(6)
'************** *************** *********

this gives me 6 letters at random.
for example utjand

i would like it to give say 3 letters and 3 numbers. is this possible with
the code i have?

TIA
Bam

Mar 31 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
23160
by: Andreas Lobinger | last post by:
Aloha, i wanted to ask another problem, but as i started to build an example... How to generate (memory and time)-efficient a string containing random characters? I have never worked with generators, so my solution at the moment is: import string import random random.seed(14)
18
9777
by: Rob Meade | last post by:
Hi all, I need to be able to create some license keys for an application. Ideally these wouldn't be too long in length (ie, easier to remember/type in), but I would like them to be auto generated and a check made to see whether or not that key has already been used, something which could generate up to about 10000 keys (or more if the string doesnt have to be too long) would be very useful. A combination of letters, numbers, upper and...
5
3109
by: Luke | last post by:
Hello, I am the administrator for http://www.nickberg.org - Nick is the man who was recently beheaded in Iraq. He was a very ingenious man - once for my birthday had gave me a small box wrapped in duck tape with a few diodes and two wires sticking out. When attaching the wires to your skin the diodes would light up in a random configuration. (he later modified this into a skin resistance
4
2205
by: anita | last post by:
I had posted this question before, but did not hear from anybody. Can somebody pls help me out. I am creating a table with two fields F1, F2 and F2 has about 50,000 randomly generated alphanumeric nos(RandomID)stored in the combobox control. Everytime I enter a new record in F1, the next available RandomID should be automatically assigned to the new record entry and displayed in the respective form control(F2). Can anybody guide me...
3
2219
by: aahmad76 | last post by:
Can anyone please help me. I am trying to desing a program that will create a 10 digit alphanumeric password. I am new to the Vb.net environment, and sometimes have no idea what to do. I appreciate any help!!! Thank you
104
5157
by: fieldfallow | last post by:
Hello all, Is there a function in the standard C library which returns a prime number which is also pseudo-random? Assuming there isn't, as it appears from the docs that I have, is there a better way than to fill an array of range 0... RAND_MAX with pre-computed primes and using the output of rand() to index into it to extract a random prime.
24
1937
by: Tuvas | last post by:
Okay, I'm working on devoloping a simple, cryptographically secure number, from a range of numbers (As one might do for finding large numbers, to test if they are prime). My function looks like this: def cran_rand(min,max): if(min>max): x=max max=min min=x range=round(log(max-min)/log(256))
3
3402
by: stjulian | last post by:
I have used set typ = server.createobject("Scriptlet.TypeLib") to create a random string of 36 characters. However, is there a way to create a random string of digits in the length I request? Perhaps a string of 20 digits with a few asterisks thrown in for ease of typing? for example: 4515-81301-75454-45136-1
3
2081
by: tshad | last post by:
I have a page that I am getting a username and password as a random number (2 letters, one number and 4 more letters) I have 2 functions I call: ************************************************* Function RandomString(size as integer, lowerCase as boolean) as string Dim builder as StringBuilder = new StringBuilder() Dim random as Random = new Random() Dim i as integer dim ch as char
0
8781
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8697
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9156
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8995
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7908
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6615
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5939
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2502
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.