Guest User

Untitled

a guest
Jul 4th, 2018
552
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 0.98 KB | None | 0 0
  1. #!/nethome/users/drmb75/tclkit85-linux-x86
  2.  
  3. ;#this generates sample files for testing
  4. ;#the multithreaded banking code for cs284
  5.  
  6. ;#the user is expected to > this to whatever file they want
  7. ;#to store the output in
  8.  
  9. ;#returns a random integer in the desired range
  10. proc rand_int {low high} {
  11.     return [expr {int(rand()*($high-$low+1)+$low)}]
  12. }
  13.  
  14. ;#variables to store various parameters
  15. ;#(none of which we are likely to change)
  16. set operations [list "d" "w" "t"]
  17. set accounts [list 0 1]
  18. set min_amount 1
  19. set max_amount 9000
  20.  
  21. set lines 500
  22.  
  23. for {set n 0} {$n<$lines} {incr n} {
  24.     set op [lindex $operations [rand_int 0 [expr {[llength $operations]-1}]]]
  25.     set account [lindex $accounts [rand_int 0 [expr {[llength $accounts]-1}]]]
  26.     set amount [rand_int $min_amount $max_amount]
  27.    
  28.     ;#the newline thing here is just a formatting issue
  29.     ;#because of how bank.c expects it
  30.     puts -nonewline "$op $account $amount"
  31.     if {$n!=[expr {$lines-1}]} {
  32.         ;#this is just a newline
  33.         puts ""
  34.     }
  35. }
Add Comment
Please, Sign In to add comment