What happened to SmallBASIC's Random number generator? Was it always this bad?
Here I was testing 1,000,000 random numbers * 1000000 to compare Sort methods, and did not get much variation!
REM SmallBASIC
REM created: 28/10/2018
'Compare RussianSorting presented by Danilin to a Basic standard QuickSort by B+ 2018-10-28"
RANDOMIZE TIMER
' Here is the only relevant parts of Danilin
CONST n = 1000000
DIM d(n) ' single
DIM a(n) ' single
DIM QS(n) ' to compare to Danilin's "simple" code
' Make a sample set of test data
FOR i = 1 TO n
r = RND * n
d(i) = r
QS(i) = r
NEXT
' Since Danilin does not provide us with "c:/N.txt" file data, can't be important to his demo
age = 1 + LOG(n) / LOG(2)
start = TIMER
IF age > 0 THEN
RussianSortingHalvesDAV 1, n, 1, age
END IF
finish = TIMER
PRINT finish - start; "second "
IF n > 100 THEN stopper = 100 ELSE stopper = n
FOR i = 1 TO stopper
PRINT d(i); ", ";
NEXT
DanilinTime = finish - start
PRINT: PRINT: INPUT "Now for the Quick Sort Test, press enter...", enter$
CLS
'now try good ole Quick Sort
start = TIMER
qSort 1, n
finish = TIMER
PRINT finish - start; "sec."
IF n > 100 THEN stopper = 100 ELSE stopper = n
FOR i = 1 TO stopper
PRINT d(i); ", ";
NEXT
QSortTime = finish - start
PRINT: PRINT: PRINT "Ha, ha, ha QSort took "; INT(QSortTime / DanilinTime * 1000) / 1000; " times longer than Danilin's Sort!"
PAUSE
SUB RussianSortingHalvesDAV (ab, yz, part, age)
local i, summa, middle, abc, xyz
IF yz - ab < 1 THEN EXIT SUB
FOR i = ab TO yz '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> really a time waster and String Array Buster here!!!!!
summa = summa + d(i)
NEXT
middle = summa / (yz - ab + 1)
abc = ab - 1
xyz = yz + 1
FOR i = ab TO yz
IF d(i) < middle THEN abc = abc + 1: a(abc) = d(i): ELSE xyz = xyz - 1: a(xyz) = d(i)
NEXT
FOR i = ab TO yz: d(i) = a(i): NEXT
IF part < age THEN
IF abc >= ab THEN RussianSortingHalvesDAV ab, abc, part + 1, age
IF xyz <= yz THEN RussianSortingHalvesDAV xyz, yz, part + 1, age
END IF
END SUB
'QS is DIM SHARED to compare to Danilin's method that needs two DIM SHARED Arrays for his SUB
SUB qSort (start, finish)
local Hi, Lo, Middle
'DIM Hi AS LONG, Lo AS LONG, Middle AS SINGLE
Hi = finish: Lo = start
Middle = QS((Lo + Hi) / 2) 'find middle of array
REPEAT
WHILE QS(Lo) < Middle: Lo = Lo + 1: WEND
WHILE QS(Hi) > Middle: Hi = Hi - 1: WEND
IF Lo <= Hi THEN
SWAP QS(Lo), QS(Hi)
Lo = Lo + 1: Hi = Hi - 1
END IF
UNTIL Lo > Hi
IF Hi > start THEN qSort start, Hi
IF Lo < finish THEN qSort Lo, finish
END SUB
You can see the repetition of values in first 100 after sort. Jump from <1 to 30.xxx