RPG attributes generator: Difference between revisions

m
syntax highlighting fixup automation
m (syntax highlighting fixup automation)
Line 36:
{{trans|Python}}
 
<langsyntaxhighlight lang="11l">random:seed(Int(Time().unix_time()))
V total = 0
V count = 0
Line 50:
total = sum(attributes)
 
print(total‘ ’attributes)</langsyntaxhighlight>
 
{{out}}
Line 59:
=={{header|8086 Assembly}}==
 
<langsyntaxhighlight lang="asm"> bits 16
cpu 8086
putch: equ 2h
Line 147:
section .bss
rnddat: resb 4 ; RNG state
attrs: resb 6 ; Rolled attributes</langsyntaxhighlight>
 
{{out}}
Line 162:
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
<syntaxhighlight lang="aarch64 assembly">
<lang AArch64 Assembly>
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program rpg64.s */
Line 398:
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"
</syntaxhighlight>
</lang>
{{Output}}
<pre>
Line 413:
 
=={{header|Action!}}==
<langsyntaxhighlight Actionlang="action!">TYPE Result=[BYTE success,sum,highCount]
BYTE FUNC GenerateAttrib()
BYTE i,v,min,sum
Line 473:
FI
OD
RETURN</langsyntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/RPG_attributes_generator.png Screenshot from Atari 8-bit computer]
Line 485:
=={{header|ALGOL 68}}==
{{Trans|Action!}}
<langsyntaxhighlight lang="algol68">BEGIN # RPG attributes generator #
 
INT attrib count = 6;
Line 537:
OD
 
END</langsyntaxhighlight>
{{out}}
<pre>
Line 549:
{{works with|Dyalog APL}}
 
<langsyntaxhighlight APLlang="apl">roll←{(+/-⌊/)¨?¨6/⊂4/6}⍣{(75≤+/⍺)∧2≤+/⍺≥15}</langsyntaxhighlight>
 
{{out}}
Line 564:
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
<syntaxhighlight lang="arm assembly">
<lang ARM Assembly>
 
/* ARM assembly Raspberry PI */
Line 888:
bx lr
 
</syntaxhighlight>
</lang>
 
=={{header|Arturo}}==
 
<langsyntaxhighlight lang="rebol">vals: []
 
while [or? 75 > sum vals
Line 906:
 
print ["values:" vals ]
print ["with sum:" sum vals]</langsyntaxhighlight>
 
=={{header|Atari BASIC}}==
{{trans|Commodore BASIC}}
<langsyntaxhighlight lang="basic">100 REM RPG character generator
110 DIM AT(5)
120 DIM AT$(18)
Line 948:
450 IF K=78 THEN 140
460 POSITION 0,13
470 PRINT "Excellent. Good luck on your adventure!"</langsyntaxhighlight>
 
{{Out}}
Line 971:
=={{header|BASIC256}}==
{{trans|FreeBASIC}}
<langsyntaxhighlight lang="freebasic">function min(a, b)
if a < b then return a else return b
end function
Line 1,006:
print "-------"
print "TOT: "; sum
end</langsyntaxhighlight>
{{out}}
<pre>Igual que la entrada de FreeBASIC.</pre>
Line 1,012:
=={{header|C}}==
{{trans|Go}}
<langsyntaxhighlight lang="c">#include <stdio.h>
#include <stdlib.h>
#include <time.h>
Line 1,053:
}
return 0;
}</langsyntaxhighlight>
 
{{out}}
Line 1,066:
=={{header|C sharp|C#}}==
{{trans|Visual Basic .NET}}
<langsyntaxhighlight lang="csharp">using System;
using System.Collections.Generic;
using System.Linq;
Line 1,097:
} while (!good);
}
}</langsyntaxhighlight>
{{out}}
sample outputs:
Line 1,106:
=={{header|C++}}==
GCC 4.9.2, unoptimised.
<langsyntaxhighlight lang="cpp">#include <algorithm>
#include <ctime>
#include <iostream>
Line 1,157:
return 0;
}</langsyntaxhighlight>
{{out}}
Sample run:
Line 1,166:
 
=={{header|Caché ObjectScript}}==
<syntaxhighlight lang="caché objectscript">RPGGEN
<lang Caché ObjectScript>RPGGEN
set attr = $lb("") ; empty list to start
write "Rules:",!,"1.) Total of 6 attributes must be at least 75.",!,"2.) At least two scores must be 15 or more.",!
Line 1,211:
} while (result '= 3)
quit</langsyntaxhighlight>
{{out}}<pre>
Line 1,227:
 
=={{header|CLU}}==
<langsyntaxhighlight lang="clu">% This program needs to be merged with PCLU's "misc" library
% to use the random number generator.
%
Line 1,296:
stream$putright(po, int$unparse(stat), 4)
end
end start_up</langsyntaxhighlight>
{{out}}
<pre>$ ./rpg_gen
Line 1,312:
Except for screen control codes, this is generic enough it could be used for many other 8-bit interpreted BASICs as well. (Applesoft, ZX Spectrum, etc.). Should work on all Commodore models. (Adjustment for screen width may be necessary on VIC-20.)
 
<langsyntaxhighlight lang="gwbasic">100 rem rpg character roller
110 rem rosetta code - commodore basic
120 dim di(3):rem dice
Line 1,351:
470 if di(x)<di(x+1) then t=di(x):di(x)=di(x+1):di(x+1)=t
480 next x
490 return</langsyntaxhighlight>
 
{{out}}
Line 1,395:
 
=={{header|Common Lisp}}==
<langsyntaxhighlight lang="lisp">
(defpackage :rpg-generator
(:use :cl)
Line 1,414:
(format t ">= 15: ~A~%" (count-if (lambda (n) (>= n 15)) scores))
(return scores)))
</syntaxhighlight>
</lang>
=={{header|Cowgol}}==
<langsyntaxhighlight lang="cowgol">include "cowgol.coh";
include "argv.coh";
 
Line 1,513:
print("\nTotal: ");
print_i8(total);
print_nl();</langsyntaxhighlight>
 
{{out}}
Line 1,528:
 
=={{header|Crystal}}==
<langsyntaxhighlight Rubylang="ruby">def roll_stat
dices = Array(Int32).new(4) { rand(1..6) }
dices.sum - dices.min
Line 1,543:
stats = roll_character
puts "stats: #{stats}, sum is #{stats.sum}"
end</langsyntaxhighlight>
 
sample output:
Line 1,561:
{{libheader| System.Generics.Collections}}
{{Trans|C#}}
<syntaxhighlight lang="delphi">
<lang Delphi>
program RPG_Attributes_Generator;
 
Line 1,675:
end.
 
</syntaxhighlight>
</lang>
 
{{out}}
Line 1,684:
=={{header|Dyalect}}==
{{trans|C#}}
<langsyntaxhighlight lang="dyalect">func getThree(n) {
var g3 = []
for i in 0..33 {
Line 1,727:
good = gs.Sum() >= 75 && hvc > 1
print(" - " + (good ? "success" : "failure"))
}</langsyntaxhighlight>
 
{{out}}
Line 1,735:
=={{header|EasyLang}}==
 
<syntaxhighlight lang="text">len v[] 6
repeat
vsum = 0
Line 1,759:
.
print "Attributes: " & " " & v[]
print "Total: " & " " & vsum</langsyntaxhighlight>
 
<pre>
Line 1,768:
=={{header|Factor}}==
{{Works with|Factor|0.98}}
<langsyntaxhighlight lang="factor">USING: combinators.short-circuit dice formatting io kernel math
math.statistics qw sequences ;
IN: rosetta-code.rpg-attributes-generator
Line 1,793:
[ "%s: %d\n" printf ] 2each nl stats-info ;
MAIN: main</langsyntaxhighlight>
{{out}}
<pre>
Line 1,808:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">#define min(a, b) iif(a < b, a, b)
 
function d6() as integer
Line 1,841:
next i
print "--------"
print using "TOT: ##";sum</langsyntaxhighlight>
{{out}}<pre>STR: 14
CON: 11
Line 1,853:
 
=={{header|FOCAL}}==
<langsyntaxhighlight FOCALlang="focal">01.10 S T=0
01.20 F X=1,6;D 4;S AT(X)=S3;S T=T+S3
01.30 I (T-75)1.1
Line 1,876:
06.01 C--ROLL A D6
06.10 S A=FRAN()*10;S A=A-FITR(A)
06.20 S A=1+FITR(A*6)</langsyntaxhighlight>
 
{{out}}
Line 1,902:
{{works with|GNU Forth}}
{{libheader|random.fs}}
<langsyntaxhighlight lang="forth">require random.fs
: d6 ( -- roll ) 6 random 1 + ;
 
Line 1,937:
;
 
utime drop seed !</langsyntaxhighlight>
 
{{Out}}
Line 1,944:
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import (
Line 1,989:
break
}
}</langsyntaxhighlight>
 
{{out}}
Line 2,001:
 
=={{header|Haskell}}==
<langsyntaxhighlight lang="haskell">import Control.Monad (replicateM)
import System.Random (randomRIO)
import Data.Bool (bool)
Line 2,019:
-------------------------- TEST ---------------------------
main :: IO ()
main = replicateM 10 character >>= mapM_ (print . (sum >>= (,)))</langsyntaxhighlight>
{{Out}}
<pre>Sample computation:
Line 2,036:
=={{header|J}}==
'twould be more efficient to work with index origin 0, then increment the roll once at output.
<syntaxhighlight lang="j">
<lang J>
roll=: 1 + 4 6 ?@:$ 6:
massage=: +/ - <./
Line 2,049:
NB. use: generate_character 'name'
generate_character=: (; (+/ ; ])@:([: generate_attributes@:show Until accept 0:))&>@:boxopen
</syntaxhighlight>
</lang>
 
 
Line 2,082:
 
=={{header|Java}}==
<langsyntaxhighlight Javalang="java">import java.util.List;
import java.util.Random;
import java.util.stream.Stream;
Line 2,115:
}
}
}</langsyntaxhighlight>
{{Out}}
<pre>
Line 2,124:
=={{header|Javascript}}==
===Imperative===
<langsyntaxhighlight lang="javascript">function roll() {
const stats = {
total: 0,
Line 2,157:
${rolledCharacter.rolls.join(', ')}
 
Their sum is ${rolledCharacter.total} and ${rolledCharacter.rolls.filter(a => a >= 15).length} of them are >= 15`);</langsyntaxhighlight>
 
{{out}}
Line 2,170:
===Functional===
{{Trans|Python}} (Functional composition version)
<langsyntaxhighlight lang="javascript">(() => {
'use strict';
 
Line 2,293:
// MAIN ---
return main();
})();</langsyntaxhighlight>
{{Out}}
A sample of 10 character attribute sets:
Line 2,308:
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">roll_skip_lowest(dice, sides) = (r = rand(collect(1:sides), dice); sum(r) - minimum(r))
 
function rollRPGtoon()
Line 2,329:
rollRPGtoon()
rollRPGtoon()
</langsyntaxhighlight>{{output}}<pre>
New RPG character roll: [15, 16, 15, 11, 9, 15]. Sum is 81, and 4 are >= 15.
New RPG character roll: [12, 14, 15, 12, 10, 16]. Sum is 79, and 2 are >= 15.
Line 2,336:
 
=={{header|Kotlin}}==
<langsyntaxhighlight lang="kotlin">import kotlin.random.Random
 
fun main() {
Line 2,351:
break
}
}</langsyntaxhighlight>
 
{{output}}
Line 2,361:
 
=={{header|Ksh}}==
<langsyntaxhighlight lang="ksh">
#!/bin/ksh
 
Line 2,432:
print "Attribute value total: ${total}"
print "Attribule count >= 15: ${cnt15}"
</syntaxhighlight>
</lang>
{{out}}<pre>
strength: 11
Line 2,444:
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">valid = False;
While[! valid,
try = Map[Total[TakeLargest[#, 3]] &,
Line 2,452:
]
]
{Total[try], try}</langsyntaxhighlight>
{{out}}
<pre>{78, {13, 15, 9, 13, 12, 16}}</pre>
Line 2,458:
=={{header|min}}==
{{works with|min|0.19.6}}
<langsyntaxhighlight lang="min">randomize ; Seed the rng with current timestamp.
 
; Implement some general operators we'll need that aren't in the library.
Line 2,474:
(big (dup special?) () (pop big) () linrec) :stats ; Roll a set of big and special attributes.
 
stats puts "Total: " print! sum puts!</langsyntaxhighlight>
{{out}}
<pre>
Line 2,482:
 
=={{header|MiniScript}}==
<langsyntaxhighlight MiniScriptlang="miniscript">roll = function()
results = []
for i in range(0,3)
Line 2,508:
end while
print "Success!"
</syntaxhighlight>
</lang>
{{out}}
<pre>Attribute values: 11, 13, 8, 10, 8, 10
Line 2,527:
 
=={{header|Nim}}==
<syntaxhighlight lang="nim">
<lang Nim>
# Import "random" to get random numbers and "algorithm" to get sorting functions for arrays.
import random, algorithm
Line 2,561:
if not twoFifteens(sixAttr) or sumAttr < 75: echo "Not good enough. Rerolling..."
else: break
</syntaxhighlight>
</lang>
 
Sample output: <pre>
Line 2,572:
=={{header|OCaml}}==
Original version by [http://rosettacode.org/wiki/User:Vanyamil User:Vanyamil]
<syntaxhighlight lang="ocaml">
<lang OCaml>
(* Task : RPG_attributes_generator *)
 
Line 2,608:
let s = valid_set () in
List.iter (fun i -> print_int i; print_string ", ") s
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 2,616:
=={{header|Pascal|FreePascal}}==
 
<syntaxhighlight lang="pascal">
<lang Pascal>
program attributes;
 
Line 2,656:
writeln(' ---');
end.
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 2,691:
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">use strict;
use List::Util 'sum';
 
Line 2,710:
 
printf "%s = %2d\n", $attr_names[$_], $attr[$_] for 0..$#attr;
printf "Sum = %d, with %d attributes >= $hero_attr_min\n", sum(@attr), heroic(@attr);</langsyntaxhighlight>
{{out}}
<pre>Str = 13
Line 2,721:
 
=={{header|Phix}}==
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">numbers</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">6</span><span style="color: #0000FF;">)</span>
Line 2,740:
<span style="color: #000000;">numbers</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\nTheir sum is %d and %d of them are &gt;=15\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">t</span><span style="color: #0000FF;">,</span><span style="color: #000000;">n</span><span style="color: #0000FF;">})</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 2,753:
=={{header|PHP}}==
===Version 1===
<langsyntaxhighlight lang="php"><?php
 
$attributesTotal = 0;
Line 2,783:
}
 
print_r($attributes);</langsyntaxhighlight>
 
===Version 2===
<langsyntaxhighlight lang="php"><?php
class CharacterGenerator {
Line 2,825:
print "Attribute Total: $attributesTotal\n";
print "Attributes: $attributesString";</langsyntaxhighlight>
 
{{out}}
Line 2,832:
 
=={{header|Plain English}}==
<langsyntaxhighlight lang="plainenglish">To add an attribute to some stats:
Allocate memory for an entry.
Put the attribute into the entry's attribute.
Line 2,911:
If the entry's next is not nil, write ", " on the console without advancing.
Put the entry's next into the entry.
Repeat.</langsyntaxhighlight>
{{out}}
<pre>
Line 2,920:
 
=={{header|PureBasic}}==
<langsyntaxhighlight lang="purebasic">#heroicAttributeMinimum = 15
#heroicAttributeCountMinimum = 2
#attributeSumMinimum = 75
Line 2,976:
Print(#CRLF$ + #CRLF$ + "Press ENTER to exit"): Input()
CloseConsole()
EndIf</langsyntaxhighlight>
Sample output:
<pre>Attributes generated: [13, 17, 17, 11, 9, 17]
Line 2,983:
=={{header|Python}}==
===Python: Simple===
<langsyntaxhighlight lang="python">import random
random.seed()
attributes_total = 0
Line 3,009:
attributes_total = sum(attributes)
print(attributes_total, attributes)</langsyntaxhighlight>
 
{{out}}
Line 3,016:
 
===Python: Nested Comprehensions #1===
<langsyntaxhighlight lang="python">import random
random.seed()
total = 0
Line 3,030:
total = sum(attributes)
print(total, attributes)</langsyntaxhighlight>
 
{{out}}
Line 3,038:
===Python: Nested Comprehensions #2===
With comprehensions for checking candidate values in the while expression.
<langsyntaxhighlight lang="python">import random
 
def compute():
Line 3,049:
for i in range(3):
print(*compute())
</syntaxhighlight>
</lang>
 
{{out}}
Line 3,059:
Composing a hero-generator from reusable functions:
{{Works with|Python|3.7}}
<langsyntaxhighlight lang="python">'''RPG Attributes Generator'''
 
from itertools import islice
Line 3,175:
 
if __name__ == '__main__':
main()</langsyntaxhighlight>
<pre>A sample of 10:
 
Line 3,191:
===Python: One-liner===
Just because you can, doesn't mean you should.
<langsyntaxhighlight lang="python">
import random; print((lambda attr: f"Attributes: {attr}\nTotal: {sum(attr)}")((lambda func, roll_func: func(func, roll_func, roll_func()))((lambda func, roll_func, rolls: rolls if sum(rolls) >= 75 and rolls.count(15) >= 2 else func(func, roll_func, roll_func())), lambda: [sum(sorted(random.randint(1, 6) for _ in range(4))[1:]) for _ in range(6)])))
</syntaxhighlight>
</lang>
<pre>
Attributes: [16, 15, 15, 14, 8, 10]
Line 3,200:
 
=={{header|Quackery}}==
<langsyntaxhighlight lang="quackery">[ 0 swap witheach + ] is sum ( [ --> n )
 
[ 0 ]'[ rot witheach
Line 3,224:
say 'Sum: ' dup sum echo cr
say '# of attributes > 14: '
count [ 14 > ] echo</langsyntaxhighlight>
{{out}}
<pre>
Line 3,234:
 
=={{header|Racket}}==
<langsyntaxhighlight lang="racket">#lang racket
 
(define (d6 . _)
Line 3,251:
(module+ main
(define-values (rolled-stats total) (generate-character))
(printf "Rolls:\t~a~%Total:\t~a" rolled-stats total))</langsyntaxhighlight>
 
{{out}}
Line 3,259:
=={{header|R}}==
The base library already has an attributes function, so we avoid using that name. Otherwise, this is R's bread and butter.
<langsyntaxhighlight lang="rsplus">genStats <- function()
{
stats <- c(STR = 0, DEX = 0, CON = 0, INT = 0, WIS = 0, CHA = 0)
Line 3,269:
if(sum(stats >= 15) < 2 || (stats["TOT"] <- sum(stats)) < 75) Recall() else stats
}
print(genStats())</langsyntaxhighlight>
 
{{out}}
Line 3,278:
(formerly Perl 6)
{{works with|Rakudo Star|2018.04.1}}
<syntaxhighlight lang="raku" perl6line>my ( $min_sum, $hero_attr_min, $hero_count_min ) = 75, 15, 2;
my @attr-names = <Str Int Wis Dex Con Cha>;
 
Line 3,291:
 
say @attr-names Z=> @attr;
say "Sum: {@attr.sum}, with {heroic(@attr)} attributes >= $hero_attr_min";</langsyntaxhighlight>
{{out}}
<pre>
Line 3,299:
 
=={{header|Red}}==
<langsyntaxhighlight lang="rebol">Red ["RPG attributes generator"]
 
raw-attribute: does [
Line 3,349:
]
 
show-attributes attributes</langsyntaxhighlight>
{{out}}
<pre>
Line 3,365:
=={{header|REXX}}==
===version 1===
<langsyntaxhighlight lang="rexx">/* REXX
Generates 4 random, whole values between 1 and 6.
Saves the sum of the 3 largest values.
Line 3,428:
swl=swl wa.i
End
Return strip(swl)</langsyntaxhighlight>
{{out}}
<pre>I:\>rexx cast
Line 3,439:
===version 2===
This REXX version doesn't need a sort to compute the sum of the largest three (of four) values.
<langsyntaxhighlight lang="rexx">/*REXX program generates values for six core attributes for a RPG (Role Playing Game).*/
do until m>=2 & $$>=75; $$= 0; list= /*do rolls until requirements are met. */
m= 0 /*the number of values ≥ 15 (so far).*/
Line 3,452:
end /*do 6*/ /* [↑] gen six core attribute values. */
end /*until*/ /*stick a fork in it, we're all done. */
say 'The total for ' list " is ──► " $$', ' m " entries are ≥ 15."</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the default (internal) inputs:}}
<pre>
Line 3,460:
===version 3===
A variation of version 2
<langsyntaxhighlight lang="rexx">/*REXX program generates values for six core attributes for an RPG (Role Playing Game).*/
Do n=1 By 1 until m>=2 & tot>=75;
slist=''
Line 3,479:
Say 'the total for' space(slist) 'is -->' tot', 'm' entries are >= 15.'
end
Say 'Solution found with' n 'iterations'</langsyntaxhighlight>
{{out}}
<pre>I:\>rexx rpg
Line 3,488:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
# Project : RPG Attributes Generator
 
Line 3,533:
line = line + "])"
see line + nl
</syntaxhighlight>
</lang>
Output:
<pre>
Line 3,540:
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">res = []
until res.sum >= 75 && res.count{|n| n >= 15} >= 2 do
res = Array.new(6) do
Line 3,550:
p res
puts "sum: #{res.sum}"
</syntaxhighlight>
</lang>
{{out}}
<pre>[12, 14, 17, 12, 16, 9]
Line 3,557:
 
=={{header|Run BASIC}}==
<langsyntaxhighlight lang="runbasic">dim statnames$(6)
data "STR", "CON", "DEX", "INT", "WIS", "CHA"
for i = 1 to 6
Line 3,589:
a = d6() : b = d6() : c = d6() : d = d6()
rollstat = a + b + c + d - min(min(a, b), min(c, d))
end function</langsyntaxhighlight>
 
=={{header|Rust}}==
Line 3,595:
{{libheader|rand}}
{{works with|Rust|2018}}
<langsyntaxhighlight lang="rust">
use rand::distributions::Uniform;
use rand::prelude::{thread_rng, ThreadRng};
Line 3,672:
}
}
</syntaxhighlight>
</lang>
{{out}}
Sample output, running the generator ten times:
Line 3,690:
 
=={{header|Scala}}==
<langsyntaxhighlight lang="scala">
import scala.util.Random
Random.setSeed(1)
Line 3,711:
 
println("picked => " + getCharacter.mkString("[", ",", "]"))
</syntaxhighlight>
</lang>
 
<pre>
Line 3,722:
 
=={{header|Seed7}}==
<langsyntaxhighlight lang="seed7">$ include "seed7_05.s7i";
 
const proc: main is func
Line 3,759:
writeln(" ----");
writeln("Total " <& total lpad 3);
end func;</langsyntaxhighlight>
 
{{out}}
Line 3,777:
{{trans|FreeBASIC}}
{{works with|QBasic}}
<langsyntaxhighlight lang="qbasic">FUNCTION min(a, b)
IF a < b THEN LET min = a ELSE LET min = b
END FUNCTION
Line 3,818:
PRINT "--------"
PRINT "TOT: "; sum
END</langsyntaxhighlight>
{{out}}
<pre>Igual que la entrada de FreeBASIC.</pre>
Line 3,824:
=={{header|uBasic/4tH}}==
{{trans|Yabasic}}
<syntaxhighlight lang="text">dim @n(6)
@n(0) := "STR"
@n(1) := "CON"
Line 3,857:
local (4)
a@ = FUNC(_d6) : b@ = FUNC(_d6) : c@ = FUNC(_d6) : d@ = FUNC(_d6)
return (a@ + b@ + c@ + d@ - Min(Min(a@, b@), Min(c@, d@)))</langsyntaxhighlight>
{{Out}}
<pre>STR: 17
Line 3,874:
{{works with|Zsh}}
 
<langsyntaxhighlight lang="sh">function main {
typeset attrs=(str dex con int wis cha)
typeset -A values
Line 3,910:
 
main "$@"
</syntaxhighlight>
</lang>
{{Out}}
<pre>str: 12
Line 3,921:
=={{header|Visual Basic .NET}}==
repeats until a successful outcome occurs
<langsyntaxhighlight lang="vbnet">Module Module1
 
Dim r As New Random
Line 3,946:
Loop Until good
End Sub
End Module</langsyntaxhighlight>
{{out}}
sample outputs:
Line 3,963:
=={{header|Wren}}==
{{libheader|Wren-sort}}
<langsyntaxhighlight lang="ecmascript">import "random" for Random
import "/sort" for Sort
 
Line 3,985:
}
}
}</langsyntaxhighlight>
 
{{out}}
Line 3,995:
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">func Gen; \Return sum of the three largest of four random values
int I, R, Min, SI, Sum, Die(4);
[Min:= 7; Sum:= 0;
Line 4,020:
[IntOut(0, Value(J)); ChOut(0, ^ )];
CrLf(0);
]</langsyntaxhighlight>
 
{{out}}
Line 4,030:
=={{header|Yabasic}}==
{{trans|FreeBASIC}}
<langsyntaxhighlight lang="freebasic">sub d6()
//simulates a marked regular hexahedron coming to rest on a plane
return 1 + int(ran(6))
Line 4,067:
next i
print "-------\nTOT: ", sum
end</langsyntaxhighlight>
{{out}}
<pre>Igual que la entrada de FreeBASIC.</pre>
 
=={{header|zkl}}==
<langsyntaxhighlight lang="zkl">reg attrs=List(), S,N;
do{
attrs.clear();
Line 4,081:
}while((S=attrs.sum(0))<75 or (N=attrs.filter('>=(15)).len())<2);
println("Random numbers: %s\nSums to %d, with %d >= 15"
.fmt(attrs.concat(","),S,N));</langsyntaxhighlight>
{{out}}
<pre>
10,327

edits