我对我的 Fortran randomwalk 代码感到困惑

I'm confused with my fortran randomwalk code

我正在做一个学校项目,我必须编写一个程序,该程序采用 1 和 0 之间的随机数,并将 at 解释为左、右或在线性图上没有变化。我不明白为什么位置不变为 0。有帮助吗? 这是:

program test
implicit none 
integer, dimension(100)::tau
integer, dimension(100)::position=0
real,dimension(100)::x
real::y,a,b
integer::n
a=1/3
b=2/3
do n=1,100
    tau(n)=n
    call random_number(y)
    x(n)=y
end do
position(1)=0
do n=1,100
  if (x(n) .le. a) then
    position(n)=position(n)+1
  else if ((x(n) .gt. a) .and. (x(n) .le. b)) then
    position(n)=position(n)-1
  else
    position(n)=position(n)+0
  end if
end do
open(unit=10, file="test.txt")
do n=1,100
    write(10,*) tau(n),x(n), position(n)
end do
close(10)
end program test

问题是你的两个实变量 'a' 和 'b' 是由整数常量定义的,所以它们都是零。

更改为:

a=1.0/3.0
b=2.0/3.0