Random in VBA?

Have you ever tried to use the “random” function in Excel? If you have, you may have noticed a pattern, which is exactly what you should not notice while running a randomizer. This is the story of how I learned that the hard way. I began my project out of a sense of irrational paranoia. Like many, I am constantly bombarded with “Use suggested password?” notifications. I immediately distrusted them. How do I know they are truly random? How do I know some devious Blackhat didn’t compromise your password generation and is logging all of the suggested passwords? How do I know I am not a brain in a vat? There was only one logical solution. Make my own password generator that would store the password in an Excel workbook.

I immediately went about making a list of the characters I would consider using in my passwords, excluding any that look too similar to another character. Goodbye Zero! Hasta la vista Sheffer Stroke! After that laborious task was complete, I wrote a short, effective (or so I foolishly though) script that would concatenate a “random” string of a specified length and store it on a worksheet along with the site that the password was for. Success! Goodbye questionable “Suggested” passwords! Hello passwords I could rely on.

I am a little embarrassed how long it took to discover the flaw in my password generator. A full 31 day month later I discovered a pattern. A shocking pattern that still haunts me. Most of my password that I had created had the exact same string, only varying in length. “SechqQW:]%&\P”. How could this be? I knew that there was a minuscule chance that two randomly generated passwords would be the same, but 80% of them being exactly the same? Something was wrong, and I wouldn’t rest until I had fixed the issue!

I immediately did a hot fix that allowed me to view the generated password before it was entered on my list and have it create another one. The first password that the sheet would suggest after opening the workbook was always the same. Every character generated by the Rnd() function went in a specific order. I began researching the function and lo and behold I discovered the issue. Excel’s “random” number generator works by outputting a value between 0 and 1. It then uses that number as a seed to generate the next number, and the new number as a seed for the next number. “But John,” you might ask, “so long as the first generated number is random, then the seeds would be random, and the function would work exactly as intended!” Yes, very good point. And here is where the problem lies. The first randomly generated number is ALWAYS THE SAME!

How could this be called “random”? How was this flaw not accounted for when designing the function? I asked myself these questions, and immediately dismissed them and set about fixing the problem at hand, which was, as it turns out, pretty simple. I made several lists of characters in random orders for the function to operate on and inserting the current time, day, and year into a formula that told the script which list to use. That done I rested easily knowing that I had passwords that were randomly generated by me. Take that “suggested” passwords!

“Paranoid? Probably. But just because you’re paranoid doesn’t mean there isn’t an invisible demon about to eat your face.”
― Jim Butcher

Previous Post

I am a developer in Albuquerque, New Mexico. I have experience in VBA and Python and am always learning more languages and tools to help me progress as a developer. I enjoy tea, brie, and D and D.
103 Responses
  1. Одновременно с этим существует и другая сторона формирования и организации высказывания.

  2. Одновременно с этим существует и другая сторона формирования и организации высказывания.

  3. Can I simply just say what a relief to find somebody that truly
    understands what they’re discussing on the internet.
    You definitely know how to bring a problem to light
    and make it important. A lot more people need to check
    this out and understand this side of the story.
    I can’t believe you aren’t more popular given that you most certainly possess the gift.

  4. I know this if off topic but I’m looking
    into starting my own blog and was curious what all is needed to
    get set up? I’m assuming having a blog like yours would cost a pretty penny?
    I’m not very internet savvy so I’m not 100% positive. Any recommendations or advice
    would be greatly appreciated. Kudos

  5. Yepyeni bir sossyal medya aracı olan ve insanlarla sohbet edebileceğiniz bir sosyal
    medya uygulaması. sadece daha önce kullandığınız uygulamalardan birazcık farklı.
    Bu tatbik sohbet edebileceğiniz bir uygulamayken,
    ancak ses verileriyle yazışma kurmanızı destekliyor.
    resim vb. benzer biçimde veriler yerine, sohbet
    odalarında ses ile kontakt kurabiliyorsunuz.
    Artık clubhose takipçi takip2018 de
    Clubhouse Takipçi Satın AL dan hemen clubhose takipçi alabilirsiniz.

  6. Great website you have here but I was wondering if you knew of any community forums that cover the same topics discussed here?
    I’d really love to be a part of group where I can get feedback from other knowledgeable individuals that share the same interest.
    If you have any recommendations, please let me know.
    Appreciate it!

  7. Hi I am so grateful I found your webpage, I really found you by mistake, while I was
    researching on Digg for something else, Regardless I am here now and would
    just like to say many thanks for a tremendous post and
    a all round enjoyable blog (I also love the theme/design), I don’t have time to
    read it all at the minute but I have saved it and also added your RSS feeds, so when I have time I will be back
    to read much more, Please do keep up the great work.

  8. Youtube Abone satın al

    Youtube abone satın alarak youtuber olmanızın zamanı geldimi?
    tam yerinde olduğunuzu lütfen unutmayınız.

    Sitemiz den vereceğiniz tüm youtube aboneleri gerçek kişilerdir.
    Seçenekler aşşağıdaki gibi paketler oluşturarak sizlere sunmuş bulunmaktayız.

    Youtube aboneler genelde hızlı başlar fakat bazen dünya geneli yoğunluk nedeni ile bu süreç 0
    – 12 saat kadar sürebilir bizi tercih ettiğiniz için şimdiden teşekkür ederiz.

    Türkiyenin Lider sosyal medya hizmetleri sağlayıcısı

    Uygun fiyat seçeneklerimizden hemen faydalanın

  9. I have been surfing online more than 4 hours today, yet I
    never found any interesting article like yours.

    It is pretty worth enough for me. Personally, if all website
    owners and bloggers made good content as you did, the internet will be
    much more useful than ever before.

  10. nstagram Takipçi Satın Alarak Kitleniz Nasıl Büyür?

    Instagram takipçi satın al günümüzde tercih edilen hesap büyütme yollarından biridir.

    Kişisel hesapların yanı sıra pek çok işletme hesabının da yer aldığı uygulamada her hesap, takipçi sayısının çok olmasını ister.
    Takipçi sayısının yüksek olması ile farklı Instagram kullanıcılarında
    güven oluşur ve sayfa ziyareti başlar. İnstagram takipçi alarak profilinizi zengin göstererek en iyi ve kaliteli takipçilere sahip olmanız
    yanı sıra ucuz fiyatlara takip2018 den instagram takipçi satın al

  11. Very great post. I just stumbled upon your blog and
    wished to say that I have really enjoyed surfing around your weblog posts.
    After all I’ll be subscribing on your feed and I am
    hoping you write again very soon!

  12. Spot on with this write-up, I actually feel this
    website needs a great deal more attention. I’ll probably be returning to see
    more, thanks for the information!

Leave a Reply