简体   繁体   中英

How to randomly pick a string from a string

I have a string that consists of 10,000 randomly generated characters but in order to proceed in my project I need to create 100 strings of length 20 from the data set.

I was wondering how I would be able to code this in python so that it picks 100 patterns of length 20 from the string without the chosen strings overlapping no pattern being repeated.

This is my current code to generate the patterns, I am not the best programmer.

Current string generator

Thanks

在此处输入图片说明

Since you do not show what you are doing with these and if repeats are or are not allowed, I will give a description of what you need to do.

  1. get the size of the full data set.

  2. generate a random number for starting index. make sure not to overrun the buffer (start index must be at least 20 characters before the end of the buffer

  3. get the slice starting at the chosen index from the buffer and put in your list

  4. delete the slice from the buffer.

  5. loop for the required number of times

  6. Now process your list.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM