一些步骤后,gym env.seed() 不再起作用

问题描述

似乎当我执行 env.seed(x) 时,它以相同的方式开始,但是在某些情节之后它开始产生差异..为什么?即使我添加 np.random.seed(0) 和 env.seed(0)

class Web_view_vehicle extends StatefulWidget {
  var choice ;
  var name_vehicle;
  Web_view_vehicle({ required this.choice,this.name_vehicle}) : super();
  @override
  _Web_view_vehicleState createState() => _Web_view_vehicleState();
}

class _Web_view_vehicleState extends State<Web_view_vehicle> {

  bool downloading = false;
  String progressstring = "";
  String path = '';
  late List data ;


  Future<String> get _localPath async {
    final directory = await getApplicationDocumentsDirectory();
    return directory.path;
  }

  Future<File> get _localFile async {
    final path = await _localPath;
    return File('$path/teste.pdf');
  }

  Future<File> writeCounter(Uint8List stream) async {
    final file = await _localFile;

    // Write the file
    return file.writeAsBytes(stream);
  }

  Future<Uint8List> fetchPost() async {
    dio dio = dio();
      var response =  await dio.get(widget.choice,onReceiveProgress: (rec,total) {
            print("Rec: $rec,Total: $total");
            if(!mounted)return;
            setState(() {
              downloading = true;
              progressstring = ((rec / total) * 100).toStringAsFixed(0) + "%";
            });
          },options: Options(responseType: ResponseType.bytes));
      final responseJson = response.data;
    if (!mounted) {
    }
    setState(() {
      downloading = false;
      progressstring = "Completed";
    });
    print("Download completed");
    return responseJson;
  }

  loadPdf() async {
    writeCounter((await fetchPost()));
    path = (await _localFile).path;
    if (!mounted) return;
    setState(() {});
  }

  @override
  void initState() {
    super.initState();
    loadPdf();

  }

  @override
  Widget build(BuildContext context) {

    Color? bgColor = Colors.grey[300];

    return Scaffold(
        backgroundColor: bgColor,appBar: AppBar(
          leading: Padding(
            padding: const EdgeInsets.fromLTRB(5.0,0.0,0.0),child: new IconButton(
                icon: new Icon(Icons.arrow_back),onpressed: (){Navigator.pop(context,true);}
            ),),title: Text('מדריך לרכב ${widget.name_vehicle}',textAlign: TextAlign.center,textDirection: TextDirection.rtl,backgroundColor: Colors.red[400],centerTitle: true,actions: <Widget>[

          ],body:
        (path.length > 5)?
        PdfViewer.openFile(path,):
        Center(child: Column(crossAxisAlignment: CrossAxisAlignment.center,mainAxisAlignment: MainAxisAlignment.center,mainAxisSize: MainAxisSize.max,children: [
        CircularProgressIndicator(),Text('טוען מדריך ${progressstring}',)
      ],))

        );
  }


}

解决方法

如果用 env.action_space.sample() 代替 np.random.randint(0,2)