Practical Randomness in Softanza
Softanza makes it simple to apply probabilities—ideal for AI simulations, statistical modeling, and game mechanics.
par Mansour Ayouni · dans le dépôt depuis le 2025-09-14 · essai de fonction · domaine Numérique et optimisation
Cet article est écrit en anglais, comme la bibliothèque.
Softanza builds on Haro’s C-based random engine by offering semantic APIs that cover the most common randomness needs in programming. Instead of low-level calls, you get expressive functions for probabilities, list shuffling, string randomization, and reproducible test data.
Probabilistic Functions
aNumbers = [ 12, 9, 10, 7, 25, 12, 9, 8 ] ? Some(aNumbers) #--> [ 12, 10, 7 ] ? Few(NumbersIn(-5:5)) #--> [ 0, -4 ] ? Most(PositiveNumbersIn(-5:5)) #--> [ 1, 2, 4, 5 ] ? Half(OddNumbersIn(-5:5)) #--> [ 1, 5 ]
illustration
Example: Loot Drop System
acTreasureChest = [ "gold", "sword", "potion", "gem", "scroll" ] acRareItems = Few(acTreasureChest) # 10% chance items ? @@(acRareItems) #--> [ "gold" ] acCommonItems = Most(acTreasureChest) # 70% chance items ? @@(acCommonItems) #--> [ "sword", "gem", "gold", "scroll" ]
illustration
For finer control, you can specify exact probabilities using the extended forms:
? SomeXT(NumbersIn(-5:5), 20/100) #--> [ -5, 0, 4 ] ? MostXT(PositiveNumbersIn(-5:5), 90/100) #--> [ 3, 4, 5, 1 ]
illustration
Configuration Functions
You can configure randomness globally: set the probability ratio for Some() and control the decimal precision (round in Haro/Softanza).
# Default configuration ? DefaultSome() #--> 0.3 # Change decimal precision (e.g., for currency) SetRandomRound(4) # Set volatility probability (25%) SetSome(0.25)
illustration
This is especially useful in domains like financial simulations, where precision and consistency matter.
Core Random Functions
For low-level randomness, Softanza provides number generators with seed control—perfect for reproducible results.
? ARandomNumber() #--> 133_322_384 ? ARandomNumberXT(77) #--> 32_438_4546
illustration
Generate test data that can be replayed identically:
nTestSeed = 12345
anUserIds = []
for i = 1 to 1000
anUserIds + ARandomNumberXT(nTestSeed + i)
next
? ShowShort(anUserIds)
#--> [ 7587, 7590, 7593, "...", 10843, 10846, 10849 ]illustration
Generating Random Numbers
Produce numbers within constraints:
? ARandomNumberLessThan(10) #--> 2 ? RandomNumberBetween(100, 150) #--> 149 ? NRandomNumbersBetweenU(3, 100, 110) #--> [ 102, 109, 105 ]
illustration
Softanza also supports negative numbers:
? random01() #--> 0.61 ? ARandomNumberBetween(-3.5, 2.8) #--> -2.45 SetRandomRound(3) ? ARandomNumberLessThan01(0.7) #--> 0.557 ? StzRandom(-10) #--> -5 ? SomeRandomNumbersBetween(-10, -1) #--> [ -10, -10, -4 ]
illustration
Random Strings and Lists
Randomness isn’t only about numbers—you can generate strings and shuffle lists too.
Q("123456789") {
? ARandomSection()
#--> "234"
? SomeRandomSections()
#--> [ "345678", "4567" ]
}
Q("SOFTANZA") {
? ARandomChar()
#--> "T"
? ARandomCharAfterPosition(4)
#--> "A"
? ARandomCharExcept("A")
#--> "S"
}illustration
Example: Password Generator
cCharSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
"0123456789" + "#!@~_" +
"abcdefghijklmnopqurstuvwxyz"
cPassword = ""
for i = 1 to 8
cPassword += Q(cCharSet).ARandomChar()
next
? cPassword
#--> @3Ond72H
#--> 2z47AD@Z
#--> LrmaUo7Zillustration
Shuffling and Sampling
# Full shuffle aDeck = [ 1, 2, 3, 4, "A", "B", "C", "D" ] o1 = new stzList(aDeck) o1.Randomize() ? @@(o1.Content()) #--> [ "D", 4, "A", 3, "C", 2, 1, "B" ] # Shuffle only numbers aDeck = [ 1, 2, 3, 4, "A", "B", "C", "D" ] o1 = new stzList(aDeck) o1.RandomizeNumbers() ? @@(o1.Content()) #--> [ 4, 1, 2, 3, "A", "B", "C", "D" ] # Shuffle only a section aDeck = [ 1, 2, 3, 4, "A", "B", "C", "D" ] o1 = new stzList(aDeck) o1.RandomizeSection(5, 8) ? @@(o1.Content()) #--> [ 1, 2, 3, 4, "D", "A", "C", "B" ]
illustration
Card Game Example
nCards = 1:52 oGameDeck = new stzList(nCards) oGameDeck.Randomize() anPlayerHand = oGameDeck.FirstN(5) ? @@(anPlayerHand) #--> [ 48, 20, 6, 51, 35 ]
illustration
And for simple item selection:
? ARandomItemIn("A":"E")
#--> B
? NRandomItemsInU(3, "A":"E")
#--> [ "B", "E", "A" ]
acPlayerChoices = [ "rock", "paper", "scissors" ]
? ARandomItemIn(acPlayerChoices)
#--> "paper"illustration
✨ With these APIs, randomness in Softanza becomes predictable when needed, configurable when required, and expressive by design.
Citer
Mansour Ayouni. « Practical Randomness in Softanza ». Softanza narrations, 2025. https://mayouni.github.io/stzsite/fr/narrations/stz-random-narrration.html
Non exécuté : son code touche aux fichiers, au réseau, à l'horloge ou au hasard. L'article est publié tel qu'il est écrit ; ses blocs sont des illustrations. Le code des articles est du code Haro. Là où un article a été écrit avant que la langue prenne son nom actuel, le nom a été changé et rien d'autre. Genre, domaine et série lus dans le nom du fichier, année tirée du premier commit : dérivés, jusqu'à ce que l'article porte son propre en-tête. Le fichier sur GitHub(s'ouvre dans un nouvel onglet)

