Modified random distribution: Difference between revisions

add FreeBASIC
(Ada version)
(add FreeBASIC)
Line 226:
[0.90, 0.95) ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 8,487
[0.95, 1.00) ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 9,543
</pre>
 
=={{header|FreeBASIC}}==
<lang freebasic>#define NRUNS 100000
#define NBINS 20
 
function modifier( x as double ) as double
return iif(x < 0.5, 2*(0.5 - x), 2*(x - 0.5))
end function
 
function modrand() as double
dim as double random1, random2
do
random1 = rnd
random2 = rnd
if random2 < modifier(random1) then
return random1
endif
loop
end function
 
function histo( byval bn as uinteger ) as string
dim as double db = NRUNS/(50*NBINS)
dim as string h
while bn > db:
h = h + "#"
bn -= db
wend
return h
end function
 
dim as uinteger bins(0 to NBINS-1), i, b
dim as double db = 1./NBINS, rand
 
randomize timer
 
for i = 1 to NRUNS
rand = modrand()
b = int(rand/db)
bins(b) += 1
next i
 
for b = 0 to NBINS-1
print using "Bin ## (#.## to #.##): & ####";b;b*db;(b+1)*db;histo(bins(b));bins(b)
next b</lang>
{{out}}
<pre>
Bin 0 (0.00 to 0.05): ############################################################################################## 9479
Bin 1 (0.05 to 0.10): #################################################################################### 8499
Bin 2 (0.10 to 0.15): ########################################################################## 7416
Bin 3 (0.15 to 0.20): ################################################################## 6650
Bin 4 (0.20 to 0.25): ###################################################### 5457
Bin 5 (0.25 to 0.30): ############################################ 4416
Bin 6 (0.30 to 0.35): ################################## 3469
Bin 7 (0.35 to 0.40): ######################## 2481
Bin 8 (0.40 to 0.45): ############## 1466
Bin 9 (0.45 to 0.50): #### 489
Bin 10 (0.50 to 0.55): #### 475
Bin 11 (0.55 to 0.60): ############## 1472
Bin 12 (0.60 to 0.65): ######################### 2548
Bin 13 (0.65 to 0.70): #################################### 3617
Bin 14 (0.70 to 0.75): ############################################# 4538
Bin 15 (0.75 to 0.80): ####################################################### 5590
Bin 16 (0.80 to 0.85): ############################################################### 6395
Bin 17 (0.85 to 0.90): ########################################################################### 7538
Bin 18 (0.90 to 0.95): #################################################################################### 8401
Bin 19 (0.95 to 1.00): ################################################################################################ 9604
</pre>
 
781

edits