在随机化arraylists
挑战确保与filelist filelist的命令顺序相交的挑战。 Collections.shuffle() is commonly used for randomization, but it generates a new random arrangement of elements, making it difficult to preserve the original relationship.
The Solution: Synchronized Shuffling
To solve this problem, we can use Collections.shuffle() twice, each time with a Random object initialized with the same seed.种子值确保两个随机对象都会产生相同的随机数序列。long seed = system.nanotime(); collections.shuffle(filelist,new andand andan(种子)); collections.shuffle(imglist,new andural(seed)); 通过对两个随机对象使用相同的种子,我们确保以相同的顺序将filelist和imglist改组。这保持了相应元素之间的关系,允许它们一起使用而没有任何差异。这确保“ e1.jpg”图像仍然对应于“ h1.txt”等等,依此类推,尽管随机化了两个阵列,但它易于与两个数组的和谐合作。
免责声明: 提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发到邮箱:[email protected] 我们会第一时间内为您处理。
Copyright© 2022 湘ICP备2022001581号-3