Search found 2851 matches

by Richard
Feb 19, 2019 5:26
Forum: General
Topic: How to "customize" the random generator?
Replies: 18
Views: 474

Re: How to "customize" the random generator?

This code generates normally distributed random numbers. Given the mean, mu, and the standard deviation, SD; x = mu + SD * probit( Rnd ) Acklam's approximation of the probit() function used here is accurate to 9 digits. '----------------------------------------------------------------------- ' gener...
by Richard
Feb 12, 2019 23:34
Forum: General
Topic: How to "customize" the random generator?
Replies: 18
Views: 474

Re: How to "customize" the random generator?

Here is a cleaned up and documented example of my code. '----------------------------------------------------------------------- ' generate integers from a set of { 0 to nmax }, where ' each outcome has an independently specified probability '---------------------------------------------------------...
by Richard
Feb 10, 2019 21:24
Forum: General
Topic: How to "customize" the random generator?
Replies: 18
Views: 474

Re: How to "customize" the random generator?

Add this to the end of my code to get 100 integers with the specified PDF.

Code: Select all

Print
For n As Integer = 1 To 100
    target = sigma * Rnd
    For i = 0 To 63
        If target <= integral( i ) Then Exit For
    Next i
    Print i;
Next n
Print
by Richard
Feb 10, 2019 20:58
Forum: General
Topic: How to "customize" the random generator?
Replies: 18
Views: 474

Re: How to "customize" the random generator?

dist( i ) contains the probability distribution of each integer coming up. Here is the code with output 10 having 100% chance, all others = 0%. ' setup an initial Probability Distribution Function Randomize Dim As Double dist( 0 To 63 ) For i As Integer = 0 To 63 dist( i ) = 0 ' an arbitrary startin...
by Richard
Feb 10, 2019 6:34
Forum: General
Topic: How to "customize" the random generator?
Replies: 18
Views: 474

Re: How to "customize" the random generator?

This code gives random integers, biassed by your arbitrary probability distribution. ' setup an initial probability distribution Randomize Dim As Double dist( 0 To 63 ) For i As Integer = 0 To 63 dist( i ) = 100/64 ' an arbitrary starting value, here percentage Next i ' you can arbitrarily change th...
by Richard
Feb 05, 2019 1:52
Forum: General
Topic: Squares
Replies: 6210
Views: 352429

Re: Squares

@Albert. Until you get an algorithm working correctly, and find a real use for it, speed is not important. To access strings Mid(,,) will be slow; string[index] will be faster for single bytes; pointers will be fastest for 1 to 8 bytes. When you convert 4 random bits to bcd = digits 0 to 9, what do ...
by Richard
Feb 03, 2019 10:17
Forum: General
Topic: Squares
Replies: 6210
Views: 352429

Re: Squares

One issue is that you are reading 8 bytes at the time from the string by using a UlongInt pointer. That produces 8 ascii digits, which then gets converted to binary, so it will fit easily in a 32 bit Ulong. It is important that the string be a multiple of 8 digits long, or there will be a bounds err...
by Richard
Feb 01, 2019 4:49
Forum: General
Topic: Squares
Replies: 6210
Views: 352429

Re: Squares

@Albert. This makes it easy to understand and does not require acres of constants. '--------------------------------------------------------- ' make working variables and constant at the same time Dim As String num8 = "00000000", txt = num8 Dim As Ulongint Ptr p_num8 = Cast( Ulongint Ptr, ...
by Richard
Jan 31, 2019 22:30
Forum: General
Topic: Squares
Replies: 6210
Views: 352429

Re: Squares

It might be fastest on your system but is not consistently faster on mine.
It is testing the speed of your cpu internal pipeline and cache for 64 bit data.
You need to examine the asm code actually generated by the compiler for each inner loop case.
by Richard
Jan 31, 2019 3:55
Forum: General
Topic: Squares
Replies: 6210
Views: 352429

Re: Squares

You DO NOT need to embed the actual number in the code to get speed, the compiler will work it out once at compile time. It comes down to the question; Which of the following five is the most obvious, and least likely to get wrong? 2^56 1uLL shl 56 Bitset( 0uLL, 56 ) &h0100000000000000uLL 720575...
by Richard
Jan 30, 2019 22:27
Forum: General
Topic: Squares
Replies: 6210
Views: 352429

Re: Squares

@Albert.
2^56 is a double precision number, with only 52 bits of accuracy.
1ULL Shl 56 is the exact number, as a long integer with 64 bits.

Code: Select all

Print 2^56
Print "  "; 1ULL Shl 56
by Richard
Jan 23, 2019 4:58
Forum: General
Topic: Squares
Replies: 6210
Views: 352429

Re: Squares

You must reverse the order you convert the elements when you fill the array of Short variables.
Convert the string in one direction, the array in the other.
by Richard
Jan 20, 2019 2:51
Forum: Community Discussion
Topic: Moderator's Environment and Tools.
Replies: 4
Views: 285

Moderator's Environment and Tools.

Following the recent call for moderator nominations. TJF. Thank you for the nomination, but I must decline, I moderate elsewhere. Dodicat is old and wise enough to sensibly turn down the invitation. Imortis has his heart in the right place, but will need to improve his telepathy. “Decimation” was a ...
by Richard
Jan 11, 2019 23:44
Forum: General
Topic: Squares
Replies: 6210
Views: 352429

Re: Squares

@Albert.
My code showed you how to propagate carry, or to repair simple examples of delayed carry. Your code must avoid delaying carry for so long that local carry overflows within your register.
by Richard
Jan 11, 2019 2:12
Forum: General
Topic: Squares
Replies: 6210
Views: 352429

Re: Squares

See; "Date and Time Functions", Date Serial and Time Serial. Now() gets the date and time in a Double.

Code: Select all

#include "vbcompat.bi"
Dim a As Double = Now()
Print Format(a, "yyyy/mm/dd hh:mm:ss")
Print Hour( a ), Minute( a ), Second( a )

Go to advanced search