Search code examples
lotus-noteslotusscript

generate random language in LotusScript


I try to generate random the language for person documents for testing in LotusScript:

Dim arr_language(0 To 10) As String
arr_language(0) = "English"
    arr_language(1) = "Spanish"
    arr_language(2) = "Chinese"
    arr_language(3) = "German"
    arr_language(4) = "Dutch"
    arr_language(5) = "Swedish"
    arr_language(6) = "French"
    arr_language(7) = "Danish"
    arr_language(8) = "Italian"
    arr_language(9) = "Polish"
    arr_language(10) = "Portugese"  

Dim language As String
language = arr_language( Round(Rnd()* UBound(arr_language) ,0) )

I notice sometimes 'language' is sometimes empty. What am I doing wrong?


Solution

  • First of all: Your code is ok although it does not produce all languages with the same probability: For 100 Users the languages English and Portuguese will appear about 4-5 times whereas the other languages will appear 10-11 times.

    If you change your code to

    language = arr_language( Int(Rnd() * (UBound(arr_language) + 1)) )
    

    Then all values will have about the same probability.

    BUT: Nonetheless your code will always produce a number between 0 and 10 and therefor the variable language will be set.

    To really answer your question you need to provide that part of the code that produces the "empty" output for language. I guess -same as Rob does- that you take that value and put it in a field an a document and there it is probably removed by a ComputeWithForm or any other means of recalulating.

    e.g. Your "Language" field might be a DialogList that does not allow new values and one or more of your array- values is not a valid entry for that field and therefor is removed (on Compute or on open)...

    If I could quess I'd say it is the value "Portugese" as in english the right spelling is "Portuguese"...