Skip to main content

Rnd()

The Rnd() function will calculate a random number between 0 and 1.  You can then multiple it by the top number of the random interval.  So if you wanted a number between 0 and 100 you would multiple it by 100 and also use the Int() function to only capture the integer portion.  In the second example I am looking for a number between 1 and 100, in order to do this I use 99 as the top number and add 1 so that if the random number comes out as 0 it will actually be 1 because I added 1 to it.

Script

'Random number between 0 and 100
Sub Main
    Dim random_number As Double
    random_number = Rnd() * 100
    MsgBox random_number
    MsgBox Int(random_number )
End Sub

'Random number between 1 and 100
Sub Main
    Dim random_number As Double
    random_number = Rnd() * 99
    MsgBox random_number
    MsgBox Int(1 + random_number )
End Sub

IDEAScript Language

avikerem Sun, 03/22/2020 - 09:12

Hi Brian
I am still with my, now old, problem of databases history. Until a real solution will be found I would like to use an ugly kludge and to create on every round of my 365 rounds journey set of databases with random names. These databases will be removed by the end of the loop and new databases with new names will take their places on the next round
 
why is it a better solution? because each database history, even if not forgotten, will not be too long and from my experience you can generate few thausands databases and Idea will still cooperate with your madness.
 
The problem is - how to create many databases in less that a second with different names. Poor rnd is not capable of generating quickly so many different numbers. It is rather limited RNG and it will take forever to concatenate 10 calls to rng on every new database I want to create. I am not sure how fast can I generate different seeds such that the little guy will not return the same number again and again.
This brings me back to the famous and immortal comics strip:
https://dilbert.com/strip/2001-10-25
All the best and good health to all of us
Avi Kerem

Brian Element Sun, 03/22/2020 - 14:10

Thanks for the laugh with the comic.  How about creating all the names first and putting them in an array and then just cycle through the array.

avikerem Sun, 03/22/2020 - 21:32

Good Idea, Thanks Brian. sometimes the simple solution is the first to be oversighted.
These pre defined names don't even have to be random