Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script>
- // Math.random() devolve números float entre 0 e 1
- // var x = Math.random();
- // document.write(Math.sqrt(x));
- var hst = new Array(10); // fazendo paple do float x[10]
- for (var i=0; i<hst.length; i++) hst[i]=0; // construindo uma matriz com 10 elementos e enchendo de 0
- var dx = 1/hst.length;
- var N = 10000;
- for (var i=0; i<N; i++) {
- var x = Math.sqrt(Math.random());
- for (var j=0; j<hst.length; j++) {
- if (x>=j*dx && x<(j+1)*dx) {
- hst[j]++;
- }
- }
- }
- for (var i=0; i<hst.length; i++) {
- document.write(hst[i] + "<br>");
- }
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement