problems in generating a list with random() function

carlosgomes shared this question 11 years ago
Answered

I'm trying to create an animation to show how to use Monte Carlo method to aproximate pi (3.14 ...).

For that, I'm using something like

abcissa = Sequence[random(), i, 1, n] (n is an integer slider)

but all the elements of that list are equal! Shouldn't every occurrance of random() function produce a (probably) different value?


Please see file I've attached.


https://ggbm.at/533675

Comments (12)

photo
1

Hi Carlos

I think that this file that I translated to Portuguese is written by Daniel Mentrard . Maybe this is what you want.

Daniel Mentrard:

http://dmentrard.free.fr/GE...


https://ggbm.at/533677


(open with pre-release)

photo
1

Ola Carlos ...


well, as I opened you file i had the same problem. So I tried to rebuild the construction at my own.

Instead of n as variable for the number of points I took 20 and did it in the same way as you did it. Every works fine and I had 20 different point.


So I wanted to change it to use n. I created a number n = 50 and changed the definition of the first Sequence, and then the fault was there! Every random-number in each List was the same. But the two lists where different.


The same problem came up, when I wanted to change my (different) points by entering the command to build the list of points again:

Punkte=Folge[(Element[xWert,i],Element[yWert,i]),i,1,20]

in Englisch: Points= Sequence[(Element[xValue,i],Element[yValue,i]),i,1,20]


Same problem, every list had only one random number! That is a bug!

Btw ... it was not important, if I use random() or the new command Random[number,number].


Regards, Birgit.

photo
1

hello

there is many files uploaded at GUM with random list of points

eg: my caleidoscope, dados2, sierpe


if you define abcissa = Sequence[random()+0*a, i, 1, n] been "a" a slider and you move the slider "a" the list of points are updated


about montecarlo you can see this

http://www.geogebra.org/for...

now it is very easy with spreadsheet but i like can do it in 3.0 version


saludos

photo
1

Okay ...


you definition works fine, even with using n as an variabel. But as soon as I make n visible to get a slider, the behaviour is as I described!


Other trial. The sliders are visible before I created to list of points. Everythink okay until I moved one of the sliders!

I cant explain why this happens. To add a file is not useful, because after reloading my Monte-Carlo-File, there is only one point.


Birgit

photo
1

hello

i have tried P=sequence[(random(),random()+0 n),i,1,n] (i use this form ever) and it work


saludos

photo
1

:laughing: I'm the best tester ever , because I can crash everything ... :smiling_imp:


Okay mathmagic ... your idea works fine. I had a slider and got masses of points. I used up to 500 and everything works fine.


For the Monte-Carlo-Method I need to know how far are the points from the middle of the Circle A(0.5,0.5), so I used the command:

P_E=Sequence[Length[Element[P,i]-A],i,1,n]


THen I wanted to move the slider n: At first, it took a long time before anything happens. Then there was only one point left! The 450 points were on the same place!


Saludos, Birgit

photo
1

hello

i thoutht that my montecarlo worked in 3.0 so i did another montecarlo in 3.1

i do not see the problem

saludos

http://www.geogebra.org/en/...

photo
1

Hy,


The problem seems to be solved in GG 3.1.100 but I've an other problem :

"sequence[if[Random[1,10]>2,0,1],i,1,100]" doesn't work. The random results in the list are the same i.e. {0,0,0 ...} or {1,1,1...}


Regards


Luc

photo
1

:laughing:


if[Random[1,10]>2,0,1]

---------------------------^^^


Sure ... Random produces Numbers from 1 to 10, but the If-Command produces the 0 and 1.

photo
1

Birgit,


Maybe my post was not clear because of my poor english. I've edit it, so that you understand the problem.

The random[] command is not revaluated when it is in an if[] command ( or in a boolean expression ).


Regards


Luc

photo
1

hello

now you must update the random value writing

sequence[if[Random[1+0 i,10]>2,0,1],i,1,100]

next versions will do it with F9 key


also you can updated the list doing

a=1

sequence[if[Random[1+0 i a,10]>2,0,1],i,1,100]


and modifying "a"

(you can suposse if you want sequence[(i,random[0,10] i-1), i,1,20] for colineal points in random line; if random updates automatically this would be unpossible)

saludos

photo
1

Thanks,


It works with random[ 1 + i*0 , 10 ] !


Best Regards

© 2019 International GeoGebra Institute