L=2;
xini=-L/2;
xlast=xini+L;
p0={xini,0};plast={xlast,0};
x0=RandomReal[{xini,xlast}];
v0=1.0;
v0x=RandomReal[{-v0,v0}];
x[t_]:=x0+v0x*t;
(*p[t_]:={x[t],0};*)


t=0.5;
Graphics[
{PointSize->0.025,Point[{p[t],p0,plast}]},PlotRange->{{xini,xlast},{-0.25,0.25}},
Axes->True,Frame->True];
Manipulate[ 
Graphics[
{PointSize->0.025,Point[{p[t],p0,plast}]},PlotRange->{{xini,xlast},{-0.25,0.25}},
Axes->True,Frame->True] ,{t,0,10,0.01}]

(***initialisation **)
L=2;xini=-L/2;xlast=xini+L;
p0={xini,0};plast={xlast,0};
x0=RandomReal[{xini,xlast}];
v0=1.0;v0x=RandomReal[{-v0,v0}];
Deltat=0.05;
iinit=0;ilast=1000;
x[iinit]=x0;
p[iinit]={x[iinit],0};

(*** end of initialisation **)

(***generating data ***)
For[i=iinit+1,i≤ilast,i++,
x[i]=x[i-1]+Deltat*v0x;
p[i]={x[i],0};
If[x[i]<xini,
delta=xini-x[i];
x[i]=xini+delta;
v0x=-v0x;
p[i]={x[i],0};
];(*end if *)
If[x[i]>xlast,
delta=x[i]-xlast;
x[i]=xlast-delta;
v0x=-v0x;
p[i]={x[i],0};
];(*end if *)
];(*end for  *)
(***end generating data ***)

(**** visualisation of output ****)
Manipulate[ Graphics[{PointSize->0.025,Point[{p[i],p0,plast}]},PlotRange->{{xini,xlast},{-0.25,0.25}},Axes->True,Frame->True] ,{i,iinit,ilast,1}]
(**** end visualisation of output ****)

L=2;
Graphics3D[Point[{RandomReal[],RandomReal[],RandomReal[]}],PlotRange->{{-L/2,L/2},{-L/2,L/2},{-L/2,L/2}}]