Advertisement
lorek123

Untitled

Nov 26th, 2014
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.17 KB | None | 0 0
  1. import wpf
  2.  
  3. from System.Windows import Application, Window, MessageBox
  4.  
  5. class MyWindow(Window):
  6.     def __init__(self):
  7.         wpf.LoadComponent(self, 'Gen.xaml')
  8.    
  9.     def Generuj_Click(self, sender, e):
  10.        
  11.         size = self.dlugosc.Text
  12.         first = self.firstvalue.Text
  13.         if isinstance(size,int) == False or isinstance(first,int) == False or size<1 or first<0 :
  14.             Messagebox.Show("To nie s¹ wartoœci ca³kowite dodatnie!")
  15.         else:
  16.             gen(size,first)
  17.  
  18.     def gen(size = 20000,first = 0): # First jest elementem zerowym ci¹gu
  19.         tablica = [first]
  20.         ciag = ''
  21.         a = 0x41C64E6D # Implementacja zgodna z ANSI C
  22.         b = 12356
  23.         m = 2 ** 32
  24.         for i in xrange (1,size):
  25.             tablica.append((a*tablica[i-1] + b) % m )
  26.             ciag += (str(bin(tablica[i])[2:]))
  27.             if len(ciag)>size:
  28.                 ciag[:size]  # utworzenie z wylosowanych ci¹gów binarnych ci¹gu o d³ugoœci size
  29.                 break
  30.         self.hexval.Text = str(hex(int(ciag,2)))[2:].__str__()
  31.         self.binval.Text = str(ciag).__str__()
  32.  
  33. if __name__ == '__main__':
  34.     Application().Run(MyWindow())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement