Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Random Numbers
#11
...And Schrodinger's cat is always alive in some other universe.

Pete Big Grin
Reply
#12
(08-28-2025, 07:06 PM)Herve Wrote: Hi,
A few years ago, I needed to obtain a long series of truly randomized numbers; I used the tools offered by https://random.org. If you are not familiar with it, I encourage you to rush to their site.
Interesting site - who knew? You did! Thanks!
Reply
#13
(08-28-2025, 07:47 PM)Pete Wrote: ...And Schrodinger's cat is always alive in some other universe.

Pete Big Grin
Schrodinger's cat solved our rodent problem but then it peed outside the litter box! 
It giveth and it taketh away!
Tongue
Reply
#14
Some time ago I thought that I would amuse myself by writing a program to generate quasi-random numbers.  And the interest would be to see if the 'randomness' would be anything like RND.  The attach code is what I came up with.  I knew that code-produced 'random number' generation had something to do with very large number manipulations.  Steve McNeill has shown how the QB64 RND function works.  The details of my attempt are not worth exploring here, and the only point of interest is how 'random' my numbers were.  The image shows a distribution of the output and the superficial analysis suggests the numbers are reasonably random, and the function worked well when replacing RND in an actual program.  A minor ( Smile ) down-side is that this function is over 1000 times slower than RND - but I was pleased!  (And I suppose that we have all attempted something similar at some idle moment).

   

Code: (Select All)
' Attempt to create a quasi-random number sequence using huge number multiplication mathematics 15/11/23
' When used instead of RND in an actual program
' this function works properly but is much, much slower - completely as expected.
' A success!
' Obviously BigNumberRND1 is quicker than BigNumberRND

CONST False = 0, True = NOT False '!!! Remove this if used in a program which has this already

PRINT BigNumberRND, BigNumberRND1 '!!! Remove this if used in a program
END '!!! Remove this if used in a program

FUNCTION BigNumberRND
    'Function generates huge numbers (18-19 figures), selects one digit
    'And strings six sequential numbers
    'And divides by 1e6 to get a number 0 - 0.999999
    STATIC Initi%%, HugeNo~&&, RanNo%%
    IF NOT Initi%% THEN
        Initi%% = True
        Timely& = INT(100 * TIMER)
        T$ = _TRIM$(STR$(Timely&))
        RanNo%% = VAL(MID$(T$, 2, 1)) '9
        'Get Primes
        Index%% = 2
        N%% = 1
        Starter~&& = 1
        WHILE N%% <= 9
            Index%% = Index%% + 1
            IsPrime%% = True
            K%% = 2
            WHILE IsPrime%% AND K%% < Index%%
                IF Index%% / K%% = Index%% \ K%% THEN IsPrime%% = False
                K%% = K%% + 1
            WEND
            IF IsPrime%% THEN
                Starter~&& = Starter~&& * Index%%
                IF N%% = 8 THEN HugeNo~&& = Starter~&& + Timely&
                IF N%% = 9 THEN HugeNo~&& = HugeNo~&& * Starter~&&
                N%% = N%% + 1
            END IF
        WEND
    END IF
    RanChr$ = ""
    FOR N%% = 1 TO 6
        BigString$ = _TRIM$(STR$(HugeNo~&&))
        RanString$ = MID$(BigString$, 5 + RanNo%%, 1)
        RanChr$ = RanChr$ + RanString$
        RanNo%% = VAL(RanString$)
        Biggy%% = False
        J%% = 1
        WHILE NOT Biggy%%
            IF VAL(MID$(BigString$, J%%, 1)) >= 2 THEN
                FirstString$ = MID$(BigString$, J%%, 9)
                Biggy%% = True
            END IF
            J%% = J%% + 1
        WEND
        Biggy%% = False
        J%% = LEN(BigString$) - 9
        WHILE NOT Biggy%%
            IF VAL(MID$(BigString$, J%%, 1)) >= 2 THEN
                SecondString$ = MID$(BigString$, J%%, 9)
                Biggy%% = True
            END IF
            J%% = J%% - 1
        WEND
        HugeNo~&& = VAL(FirstString$) * VAL(SecondString$)
    NEXT N%%
    BigNumberRND = VAL(RanChr$) / 1E6
END FUNCTION

FUNCTION BigNumberRND1
    'Function generates huge numbers (18-19 figures), selects six sequential digits
    'And divides by 1e6 to get a number 0 - 0.999999
    STATIC Initi%%, HugeNo~&&, RanNo%%
    IF NOT Initi%% THEN
        Initi%% = True
        Timely& = INT(100 * TIMER)
        T$ = _TRIM$(STR$(Timely&))
        RanNo%% = VAL(MID$(T$, 2, 1)) '9
        'Get Primes
        Index%% = 2
        N%% = 1
        Starter~&& = 1
        WHILE N%% <= 9
            Index%% = Index%% + 1
            IsPrime%% = True
            K%% = 2
            WHILE IsPrime%% AND K%% < Index%%
                IF Index%% / K%% = Index%% \ K%% THEN IsPrime%% = False
                K%% = K%% + 1
            WEND
            IF IsPrime%% THEN
                Starter~&& = Starter~&& * Index%%
                IF N%% = 8 THEN HugeNo~&& = Starter~&& + Timely&
                IF N%% = 9 THEN HugeNo~&& = HugeNo~&& * Starter~&&
                N%% = N%% + 1
            END IF
        WEND
    END IF
    BigString$ = _TRIM$(STR$(HugeNo~&&))
    RanString$ = MID$(BigString$, 5 + RanNo%%, 1)
    RNDTemp! = VAL(MID$(BigString$, 1 + RanNo%%, 6)) / 1E6
    RanNo%% = VAL(RanString$)
    Biggy%% = False
    J%% = 1
    WHILE NOT Biggy%%
        IF VAL(MID$(BigString$, J%%, 1)) >= 2 THEN
            FirstString$ = MID$(BigString$, J%%, 9)
            Biggy%% = True
        END IF
        J%% = J%% + 1
    WEND
    Biggy%% = False
    J%% = LEN(BigString$) - 9
    WHILE NOT Biggy%%
        IF VAL(MID$(BigString$, J%%, 1)) >= 2 THEN
            SecondString$ = MID$(BigString$, J%%, 9)
            Biggy%% = True
        END IF
        J%% = J%% - 1
    WEND
    HugeNo~&& = VAL(FirstString$) * VAL(SecondString$)
    BigNumberRND1 = RNDTemp!
END FUNCTION
Reply
#15
i'm learning common lisp.

where i discovered something.  the great experts at programming.  don't know how to make "platform independent."

so be glad basic has randomize timer.  that's all folks.
Reply
#16
Cloudflare uses lava 100 lamps to generate random numbers for use in cryptogrophy:

https://blog.cloudflare.com/randomness-1...roduction/

Pretty neat stuff.

[Image: lava-lamps.jpg]
Reply
#17
It only works because nobody would ever want to steal anything from anybody who who owned a lava lamp, least of all 100 of them!

Pete

- The 70's called and they say they're doing fine without me!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Strings - Numbers Kernelpanic 0 110 01-20-2026, 10:29 PM
Last Post: Kernelpanic
  using pseudo-random numbers for repeatable content - kind of a neat trick madscijr 5 992 02-13-2025, 11:12 PM
Last Post: Pete
  random numbers badger 8 1,375 11-08-2024, 02:22 AM
Last Post: DANILIN
  Identifying colour attributes with negative numbers CharlieJV 1 572 01-28-2023, 05:16 AM
Last Post: CharlieJV
  Anybody use decimals for line numbers? Pete 6 1,108 08-05-2022, 03:28 AM
Last Post: bplus

Forum Jump:


Users browsing this thread: 1 Guest(s)