Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
42
Task/Knuth-shuffle/Vedit-macro-language/knuth-shuffle.vedit
Normal file
42
Task/Knuth-shuffle/Vedit-macro-language/knuth-shuffle.vedit
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
// Test main
|
||||
#90 = Time_Tick // seed for random number generator
|
||||
#99 = 20 // number of items in the array
|
||||
|
||||
IT("Before:") IN
|
||||
for (#100 = 0; #100 < #99; #100++) {
|
||||
#@100 = #100
|
||||
Num_Ins(#@100, LEFT+NOCR) IT(" ")
|
||||
}
|
||||
IN
|
||||
|
||||
Call("SHUFFLE_NUMBERS")
|
||||
|
||||
IT("After:") IN
|
||||
for (#100 = 0; #100 < #99; #100++) {
|
||||
Num_Ins(#@100, LEFT+NOCR) IT(" ")
|
||||
}
|
||||
IN
|
||||
Return
|
||||
|
||||
//--------------------------------------------------------------
|
||||
// Shuffle numeric registers #0 to #nn
|
||||
// #99 = number of registers to shuffle (nn-1)
|
||||
//
|
||||
:SHUFFLE_NUMBERS:
|
||||
for (#91 = #99-1; #91 > 0; #91--) {
|
||||
Call("RANDOM")
|
||||
#101 = Return_Value
|
||||
#102 = #@101; #@101 = #@91; #@91 = #102
|
||||
}
|
||||
Return
|
||||
|
||||
//--------------------------------------------------------------
|
||||
// Generate random numbers in range 0 <= Return_Value < #91
|
||||
// #90 = Seed (0 to 0x7fffffff)
|
||||
// #91 = Scaling (0 to 0x10000)
|
||||
//
|
||||
:RANDOM:
|
||||
#92 = 0x7fffffff / 48271
|
||||
#93 = 0x7fffffff % 48271
|
||||
#90 = (48271 * (#90 % #92) - #93 * (#90 / #92)) & 0x7fffffff
|
||||
Return ((#90 & 0xffff) * #91 / 0x10000)
|
||||
Loading…
Add table
Add a link
Reference in a new issue