File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -536,7 +536,12 @@ def block_diagonal(*params)
536536 def random ( shape , opts = { } )
537537 scale = opts . delete ( :scale ) || 1.0
538538
539- rng = Random . new
539+ if opts [ :seed ] . nil?
540+ rng = Random . new
541+ else
542+ rng = Random . new ( opts [ :seed ] )
543+ end
544+
540545
541546 random_values = [ ]
542547
Original file line number Diff line number Diff line change 137137 expect ( m . dtype ) . to eq ( :float64 )
138138 end
139139
140+ it "creates a matrix of random numbers with defined seed value" do
141+ m1 = NMatrix . random ( 2 , :seed => 62 )
142+ m2 = NMatrix . random ( 2 , :seed => 62 )
143+ m3 = NMatrix . random ( 2 , :seed => 65 )
144+
145+
146+ expect ( m1 ) . to eq ( m2 )
147+ expect ( m1 ) . not_to eq ( m3 )
148+
149+ end
150+
140151 it "creates a complex matrix of random numbers" do
141152 m = NMatrix . random ( 2 , :dtype => :complex128 )
142153 end
You can’t perform that action at this time.
0 commit comments