Mercurial > octave-nkf
comparison src/DLD-FUNCTIONS/rand.cc @ 11586:12df7854fa7c
strip trailing whitespace from source files
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 20 Jan 2011 17:24:59 -0500 |
parents | 01f703952eff |
children | 4d777e05d47c |
comparison
equal
deleted
inserted
replaced
11585:1473d0cf86d2 | 11586:12df7854fa7c |
---|---|
247 double d = args(idx+1).double_value (); | 247 double d = args(idx+1).double_value (); |
248 | 248 |
249 if (! error_state) | 249 if (! error_state) |
250 octave_rand::seed (d); | 250 octave_rand::seed (d); |
251 } | 251 } |
252 else if (args(idx+1).is_string () | 252 else if (args(idx+1).is_string () |
253 && args(idx+1).string_value() == "reset") | 253 && args(idx+1).string_value() == "reset") |
254 octave_rand::reset (); | 254 octave_rand::reset (); |
255 else | 255 else |
256 error ("%s: seed must be a real scalar", fcn); | 256 error ("%s: seed must be a real scalar", fcn); |
257 } | 257 } |
260 if (args(idx+1).is_string () | 260 if (args(idx+1).is_string () |
261 && args(idx+1).string_value() == "reset") | 261 && args(idx+1).string_value() == "reset") |
262 octave_rand::reset (fcn); | 262 octave_rand::reset (fcn); |
263 else | 263 else |
264 { | 264 { |
265 ColumnVector s = | 265 ColumnVector s = |
266 ColumnVector (args(idx+1).vector_value(false, true)); | 266 ColumnVector (args(idx+1).vector_value(false, true)); |
267 | 267 |
268 if (! error_state) | 268 if (! error_state) |
269 octave_rand::state (s, fcn); | 269 octave_rand::state (s, fcn); |
270 } | 270 } |
466 %! x = rand(100000,1); | 466 %! x = rand(100000,1); |
467 %! assert(max(x)<1.); %*** Please report this!!! *** | 467 %! assert(max(x)<1.); %*** Please report this!!! *** |
468 %! assert(min(x)>0.); %*** Please report this!!! *** | 468 %! assert(min(x)>0.); %*** Please report this!!! *** |
469 %! assert(mean(x),0.5,0.0024); | 469 %! assert(mean(x),0.5,0.0024); |
470 %! assert(var(x),1/48,0.0632); | 470 %! assert(var(x),1/48,0.0632); |
471 %! assert(skewness(x),0,0.012); | 471 %! assert(skewness(x),0,0.012); |
472 %! assert(kurtosis(x),-6/5,0.0094); | 472 %! assert(kurtosis(x),-6/5,0.0094); |
473 %! endif | 473 %! endif |
474 %!test | 474 %!test |
475 %! if (__random_statistical_tests__) | 475 %! if (__random_statistical_tests__) |
476 %! % statistical tests may fail occasionally. | 476 %! % statistical tests may fail occasionally. |
478 %! x = rand(100000,1); | 478 %! x = rand(100000,1); |
479 %! assert(max(x)<1.); %*** Please report this!!! *** | 479 %! assert(max(x)<1.); %*** Please report this!!! *** |
480 %! assert(min(x)>0.); %*** Please report this!!! *** | 480 %! assert(min(x)>0.); %*** Please report this!!! *** |
481 %! assert(mean(x),0.5,0.0024); | 481 %! assert(mean(x),0.5,0.0024); |
482 %! assert(var(x),1/48,0.0632); | 482 %! assert(var(x),1/48,0.0632); |
483 %! assert(skewness(x),0,0.012); | 483 %! assert(skewness(x),0,0.012); |
484 %! assert(kurtosis(x),-6/5,0.0094); | 484 %! assert(kurtosis(x),-6/5,0.0094); |
485 %! endif | 485 %! endif |
486 */ | 486 */ |
487 | 487 |
488 | 488 |
1032 octave_value retval; | 1032 octave_value retval; |
1033 | 1033 |
1034 if (nargin == 1 || nargin == 2) | 1034 if (nargin == 1 || nargin == 2) |
1035 { | 1035 { |
1036 octave_idx_type n, m; | 1036 octave_idx_type n, m; |
1037 | 1037 |
1038 if (nargin == 2) | 1038 if (nargin == 2) |
1039 m = args(1).idx_type_value (true); | 1039 m = args(1).idx_type_value (true); |
1040 else | 1040 else |
1041 m = 1; | 1041 m = 1; |
1042 | 1042 |
1083 // Convert to doubles, reusing r. | 1083 // Convert to doubles, reusing r. |
1084 for (octave_idx_type i = 0, l = m*n; i < l; i++) | 1084 for (octave_idx_type i = 0, l = m*n; i < l; i++) |
1085 rvec[i] = ivec[i] + 1; | 1085 rvec[i] = ivec[i] + 1; |
1086 | 1086 |
1087 // Now create an array object with a cached idx_vector. | 1087 // Now create an array object with a cached idx_vector. |
1088 retval = new octave_matrix (r, idx_vector (idx)); | 1088 retval = new octave_matrix (r, idx_vector (idx)); |
1089 } | 1089 } |
1090 } | 1090 } |
1091 else | 1091 else |
1092 print_usage (); | 1092 print_usage (); |
1093 | 1093 |