Results 1 to 9 of 9

Shuffle this array, or else, fix my randomisation...

Threaded View

  1. #1
    Registered User
    Join Date
    02-05-2012
    Location
    Milton Keynes, England
    MS-Off Ver
    365
    Posts
    87

    Shuffle this array, or else, fix my randomisation...

    I have a macro that creates an array, populates it with random numbers then dumps it into a sheet.

    Its quite large, and I'm seeing obvious patterns in the output, so doesn't look remotely random... I've added a test workbook, but depending on PC spec, might not run in a friendly manner... Be warned. Iv'e cut it down as small as I can to be able to see the results... my actual scrip populates 333x333 cells, this does 50x50

    My question is either...

    Can someone spot anything in my code that would make this more random

    OR

    Can I shuffle the array a few times after it's created, so add some more "randomness" to it?


    This code was created from tutorials and forum posts, I'm "OK" at vba, but quite novice.

    Sub MAP_CREATOR()
    
        Dim MapArray() As Integer                                               ' Tried as Byte, didn't work...
        Dim SysType As Byte
        Dim TheRange As Range
        Dim CellsDown As Long, CellsAcross As Long
        
        Randomize
        
        Worksheets("MAP_VISUAL").Activate
        
        'Turn off Application updates, calculations, and events
        With Application
            .Calculation = xlCalculationManual
            .EnableEvents = False
            .ScreenUpdating = False
        End With
        
        '   Set these to the size of my map
        CellsDown = 333
        CellsAcross = 333
        
        '   Redimension temporary array
        ReDim MapArray(1 To CellsDown, 1 To CellsAcross)
         
        '   Set worksheet range
        Set TheRange = Range(Cells(1, 1), Cells(CellsDown, CellsAcross))
        
        For AR = 1 To CellsDown
            For AC = 1 To CellsAcross
                Randomize
                MapArray(AR, AC) = Int((12001 - 1 + 1) * Rnd + 1)
            Next AC
        Next AR
        
        With Range("A1")
            .CurrentRegion.ClearContents
            .Resize(CellsDown, CellsDown) = MapArray
       End With
        
        'TheRange.Value = MapArray
        'Worksheets("MAP").Range("A1:CV100").Value = MapArray
        
        With Application
            .Calculation = xlCalculationAutomatic
            .EnableEvents = True
            .ScreenUpdating = True
        End With
    
    End Sub
    Many thanks in advance for anyones time and help, regardless of whether it solves my issue.
    Attached Files Attached Files
    Last edited by Darth269; 11-21-2020 at 08:09 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Smart Randomisation
    By archiplexus in forum Excel General
    Replies: 1
    Last Post: 11-14-2018, 01:12 PM
  2. [SOLVED] Shuffle array VBA
    By sigit21 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 09-18-2018, 05:47 AM
  3. [SOLVED] Improving array shuffle
    By Kyle123 in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 09-17-2015, 09:25 AM
  4. [SOLVED] Weird randomisation issue with nested rand() functions
    By qdtruong in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 09-13-2015, 01:10 PM
  5. [SOLVED] Shuffle array (Scheduling)
    By hcyeap in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 03-22-2015, 08:59 AM
  6. Formula & Index randomisation
    By mr63249 in forum Excel - New Users/Basics
    Replies: 3
    Last Post: 11-15-2008, 09:31 PM
  7. [SOLVED] Shuffle Array
    By Rik Smith in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-24-2005, 12:05 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1