[英]How to use random numbers that executes a one dimensional random walk in python?
Start with a one dimensional space of length m, where m = 2 * n + 1. Take a step either to the left or to the right at random, with equal probability. 从长度为m的一维空间开始,其中m = 2 * n +1。以等概率随机向左或向右迈出一步。 Continue taking random steps until you go off one edge of the space, for which I'm using while 0 <= position < m.
继续采取随机步骤,直到离开该空间的某一边缘为止,我正在使用该边缘,而0 <= position <m。
We have to write a program that executes the random walk. 我们必须编写一个执行随机游走的程序。 We have to create a 1D space using size n = 5 and place the marker in the middle.
我们必须使用大小n = 5创建一维空间,并将标记放置在中间。 Every step, move it either to the left or to the right using the random number generator.
每一步,使用随机数生成器将其向左或向右移动。 There should be an equal probability that it moves in either direction.
它朝两个方向移动的可能性均应相等。
I have an idea for the plan but do not know how to write it in python: 我对计划有一个想法,但不知道如何用python编写它:
None
?) None
?)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.