# Web Development

## General discussion

Locked

### random number generation

By ·
I need a small program that will generate random numbers. Criteria is: use the numbers 1-5, must be 6 characters long, no less, no more, no identical values, and no more than two occurances in a row.
Examples are: 123451 and 123451 (identical values) is bad. 434345 is good, 124445 is bad (more than two occurances in a row).
This needs to be done in some type of common format such as Excel, or as a stand alone program. It is required to print the values only, (prefer multiple columns per sheet,) but also viewing the values is better.

This conversation is currently closed to new comments.

4 total posts (Page 1 of 1)
Thread display: Collapse - | Expand +

## All Comments

Collapse -

### random number generation

by In reply to random number generation

Const CountOfNumbers = 500
Const CountOfRows = 5

Private Function GetRandomDigit1_5() As Integer
GetRandomDigit1_5 = Int((5 * Rnd) + 1)
End Function

Private Function GetRandomNumber() As Long
Dim i As Integer
Dim LastDigit As Integer, Repetitions As Integer
Dim CurrentDigit As Integer
Dim Number As String

LastDigit = 0
Repetitions = 0
Number = ""

i = 1
While i <= 6
CurrentDigit = GetRandomDigit1_5()
If CurrentDigit = LastDigit Then
Repetitions = Repetitions + 1
Else
Repetitions = 0
LastDigit = CurrentDigit
End If

If Repetitions < 2 Then
Number = Number + CStr(LastDigit)
i = i + 1
End If
Wend

GetRandomNumber = CLng(Number)
End Function

Public Sub GenerateRandomNumbers()
Dim i As Long
Dim CurrentRow As Integer

Randomize

For i = 1 To CountOfNumbers \ CountOfRows For CurrentRow = 1 To CountOfRows
Sheet1.Cells(i, CurrentRow) = GetRandomNumber
Next
Next
End Sub

Collapse -

### random number generation

by In reply to random number generation

Hurray!
Thank you very much!

Kevin

Collapse -

### random number generation

by In reply to random number generation

This is an Excel Macro

Collapse -

### random number generation

by In reply to random number generation

This question was closed by the author

Back to Web Development Forum
4 total posts (Page 1 of 1)

## Related Discussions

• 8

tcavadias ·

• 11

tcavadias ·

• 2

karmaseo ·

• 8

Indglobal ·

• 27

#### What are the main factors in SEO to rank up the website

Morgan12345 ·