Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 110
Default Random generation.

Hi NG


I have maked this Code generator.


Option Explicit

Sub CodeGen()
Dim getcode As String
Dim x As Long

Open Application.ThisWorkbook.Path & "\" _
& Date & ".txt" For Output As #1

For x = 1 To 200
getcode = CodeGenerate(32, "1234567890ABCDEF")

'// Data To file
Print #1, getcode
Next x

Close #1
'Stop
End Sub


Function CodeGenerate(qty As Long, Str As String) As String
Dim x As Long
Dim y As Long
Dim Myvalue As String

For x = 1 To Len(Str)
Dim data() As Variant
ReDim Preserve data(1 To x)
data(x) = Mid(Str, x, 1)
Next x

'// Generate
For y = 1 To qty

'// Random ?????
Randomize Date * Time '* Rnd

'// Chr
Myvalue = data(Int((Len(Str) - 1 + 1) * Rnd + 1))

'// Make CodeString
If CodeGenerate = vbNullString Then
CodeGenerate = Myvalue
Else
CodeGenerate = CodeGenerate & Myvalue
End If
Next y
End Function



when I use only Date * Time:
'// Random ?????
Randomize Date * Time
I get blocks of 8 unique lines below each other, why?


when I use Date * Time * Rnd:
'// Random ?????
Randomize Date * Time * Rnd
then I get unique lines below each other, why?

How do I get optimal Randomize within Windows/Excel?

Can I find a sort of add-in for a "better" algorithm to my Random
generation?


Best Regards
Joergen Bondesen


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 947
Default Random generation.

when I use only Date * Time:
Randomize Date * Time
I get blocks of 8 unique lines below each other, why?


My guess is that the value of Date * Time is "almost" constant during your
loop.
You get the same results if you called Randomize with a constant.
Try it with just Randomize 3

It appears that Randomize doesn't use the full 15 digits in its routine.
By including Rnd, you get values that are different.

Randomize Date * Time * Rnd

--
HTH :)
Dana DeLouis
Windows XP & Office 2003


"Joergen Bondesen" wrote in message
...
Hi NG


I have maked this Code generator.


Option Explicit

Sub CodeGen()
Dim getcode As String
Dim x As Long

Open Application.ThisWorkbook.Path & "\" _
& Date & ".txt" For Output As #1

For x = 1 To 200
getcode = CodeGenerate(32, "1234567890ABCDEF")

'// Data To file
Print #1, getcode
Next x

Close #1
'Stop
End Sub


Function CodeGenerate(qty As Long, Str As String) As String
Dim x As Long
Dim y As Long
Dim Myvalue As String

For x = 1 To Len(Str)
Dim data() As Variant
ReDim Preserve data(1 To x)
data(x) = Mid(Str, x, 1)
Next x

'// Generate
For y = 1 To qty

'// Random ?????
Randomize Date * Time '* Rnd

'// Chr
Myvalue = data(Int((Len(Str) - 1 + 1) * Rnd + 1))

'// Make CodeString
If CodeGenerate = vbNullString Then
CodeGenerate = Myvalue
Else
CodeGenerate = CodeGenerate & Myvalue
End If
Next y
End Function



when I use only Date * Time:
'// Random ?????
Randomize Date * Time
I get blocks of 8 unique lines below each other, why?


when I use Date * Time * Rnd:
'// Random ?????
Randomize Date * Time * Rnd
then I get unique lines below each other, why?

How do I get optimal Randomize within Windows/Excel?

Can I find a sort of add-in for a "better" algorithm to my Random
generation?


Best Regards
Joergen Bondesen




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 947
Default Random generation.

getcode = CodeGenerate(32, "1234567890ABCDEF")

Hi. For Random Hex Codes, here's something a little different:

Function MakeHexCode(n As Long) As String
'- - - - - - - - - - - - - - - - - - -
'// n = Number of Characters [0-9 A-F]
'- - - - - - - - - - - - - - - - - - -

Dim FSO
Dim s As String
Set FSO = CreateObject("Scripting.FileSystemObject")

Do While Len(s) < n
s = s & Mid$(FSO.GetTempName, 4, 5)
Loop
MakeHexCode = Left$(s, n)
End Function

--
HTH :)
Dana DeLouis
Windows XP & Office 2003


"Dana DeLouis" wrote in message
...
when I use only Date * Time:
Randomize Date * Time
I get blocks of 8 unique lines below each other, why?


My guess is that the value of Date * Time is "almost" constant during your
loop.
You get the same results if you called Randomize with a constant.
Try it with just Randomize 3

It appears that Randomize doesn't use the full 15 digits in its routine.
By including Rnd, you get values that are different.

Randomize Date * Time * Rnd

--
HTH :)
Dana DeLouis
Windows XP & Office 2003


"Joergen Bondesen" wrote in message
...
Hi NG


I have maked this Code generator.


Option Explicit

Sub CodeGen()
Dim getcode As String
Dim x As Long

Open Application.ThisWorkbook.Path & "\" _
& Date & ".txt" For Output As #1

For x = 1 To 200
getcode = CodeGenerate(32, "1234567890ABCDEF")

'// Data To file
Print #1, getcode
Next x

Close #1
'Stop
End Sub


Function CodeGenerate(qty As Long, Str As String) As String
Dim x As Long
Dim y As Long
Dim Myvalue As String

For x = 1 To Len(Str)
Dim data() As Variant
ReDim Preserve data(1 To x)
data(x) = Mid(Str, x, 1)
Next x

'// Generate
For y = 1 To qty

'// Random ?????
Randomize Date * Time '* Rnd

'// Chr
Myvalue = data(Int((Len(Str) - 1 + 1) * Rnd + 1))

'// Make CodeString
If CodeGenerate = vbNullString Then
CodeGenerate = Myvalue
Else
CodeGenerate = CodeGenerate & Myvalue
End If
Next y
End Function



when I use only Date * Time:
'// Random ?????
Randomize Date * Time
I get blocks of 8 unique lines below each other, why?


when I use Date * Time * Rnd:
'// Random ?????
Randomize Date * Time * Rnd
then I get unique lines below each other, why?

How do I get optimal Randomize within Windows/Excel?

Can I find a sort of add-in for a "better" algorithm to my Random
generation?


Best Regards
Joergen Bondesen






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 110
Default Random generation.

Hi Dana

Try it with just Randomize 3

It give the same probleme as Date * Time

but with your function I have generated 1000000 unique codes and that is
very good, thanks.

--
Best regards
Joergen Bondesen


"Dana DeLouis" wrote in message
...
getcode = CodeGenerate(32, "1234567890ABCDEF")


Hi. For Random Hex Codes, here's something a little different:

Function MakeHexCode(n As Long) As String
'- - - - - - - - - - - - - - - - - - -
'// n = Number of Characters [0-9 A-F]
'- - - - - - - - - - - - - - - - - - -

Dim FSO
Dim s As String
Set FSO = CreateObject("Scripting.FileSystemObject")

Do While Len(s) < n
s = s & Mid$(FSO.GetTempName, 4, 5)
Loop
MakeHexCode = Left$(s, n)
End Function

--
HTH :)
Dana DeLouis
Windows XP & Office 2003


"Dana DeLouis" wrote in message
...
when I use only Date * Time:
Randomize Date * Time
I get blocks of 8 unique lines below each other, why?


My guess is that the value of Date * Time is "almost" constant during
your loop.
You get the same results if you called Randomize with a constant.
Try it with just Randomize 3

It appears that Randomize doesn't use the full 15 digits in its routine.
By including Rnd, you get values that are different.

Randomize Date * Time * Rnd

--
HTH :)
Dana DeLouis
Windows XP & Office 2003


"Joergen Bondesen" wrote in message
...
Hi NG


I have maked this Code generator.


Option Explicit

Sub CodeGen()
Dim getcode As String
Dim x As Long

Open Application.ThisWorkbook.Path & "\" _
& Date & ".txt" For Output As #1

For x = 1 To 200
getcode = CodeGenerate(32, "1234567890ABCDEF")

'// Data To file
Print #1, getcode
Next x

Close #1
'Stop
End Sub


Function CodeGenerate(qty As Long, Str As String) As String
Dim x As Long
Dim y As Long
Dim Myvalue As String

For x = 1 To Len(Str)
Dim data() As Variant
ReDim Preserve data(1 To x)
data(x) = Mid(Str, x, 1)
Next x

'// Generate
For y = 1 To qty

'// Random ?????
Randomize Date * Time '* Rnd

'// Chr
Myvalue = data(Int((Len(Str) - 1 + 1) * Rnd + 1))

'// Make CodeString
If CodeGenerate = vbNullString Then
CodeGenerate = Myvalue
Else
CodeGenerate = CodeGenerate & Myvalue
End If
Next y
End Function



when I use only Date * Time:
'// Random ?????
Randomize Date * Time
I get blocks of 8 unique lines below each other, why?


when I use Date * Time * Rnd:
'// Random ?????
Randomize Date * Time * Rnd
then I get unique lines below each other, why?

How do I get optimal Randomize within Windows/Excel?

Can I find a sort of add-in for a "better" algorithm to my Random
generation?


Best Regards
Joergen Bondesen








Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
random letter generation Ann Excel Worksheet Functions 5 May 30th 08 06:52 PM
Random Name Generation Fleone Excel Programming 5 April 26th 06 09:18 PM
Random Name Generation pkbro Excel Worksheet Functions 1 June 21st 05 02:03 AM
Random Generation lordofthe9 Excel Programming 5 May 5th 05 03:58 PM
random number generation nyn04[_5_] Excel Programming 3 September 22nd 04 02:13 PM


All times are GMT +1. The time now is 10:43 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"