Random numbers: Difference between revisions
Content added Content deleted
(Yo freebasic yo...) |
No edit summary |
||
Line 29: | Line 29: | ||
Rnd * 10 |
Rnd * 10 |
||
'random number in the range of 0 to 10 |
Revision as of 16:39, 15 May 2007
Random numbers
You are encouraged to solve this task according to the task description, using any language you may know.
You are encouraged to solve this task according to the task description, using any language you may know.
The goal of this task is to generate a 1000-element array (vector, list, whatever it's called in your language) filled with normally distributed random numbers with a mean of 1.0 and a standard deviation of 0.5
Java
Double[] list = new Double[1000]; for(int i = 0;i<list.length;i++) { Double n; while((n=Math.random()) > 0.5); // Continue to randomize until the value is or below 0.5. list[i] = 1 + n; }
IDL
result = 1.0 + 0.5*randomn(seed,1000)
Tcl
proc nrand {} {return [expr sqrt(-2*log(rand()))*cos(4*acos(0)*rand())]} for {set i 0} {$i < 1000} {incr i} {lappend result [expr 1+.5*nrand()]}
freeBasic
Rnd * 10