Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vector最大能生成长度为多少的不重复序列? #54

Open
schrodingercatss opened this issue Feb 21, 2019 · 1 comment
Open

Comments

@schrodingercatss
Copy link

我想生成一个1e5的不重复数列,但是提示数据太大,Vector能生成的最大数量是多少呢?

@StevenJinyanCheng
Copy link

>>> import cyaron as cy
>>> l = cy.Vector.random(100000,)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\_____\AppData\Roaming\Python\Python311\site-packages\cyaron\vector.py", line 53, in random
    raise Exception("1st param is so large that CYaRon can not generate unique vectors")
Exception: 1st param is so large that CYaRon can not generate unique vectors
>>> l = cy.Vector.random(100000, [10])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\_____\AppData\Roaming\Python\Python311\site-packages\cyaron\vector.py", line 53, in random
    raise Exception("1st param is so large that CYaRon can not generate unique vectors")
Exception: 1st param is so large that CYaRon can not generate unique vectors
>>> l = cy.Vector.random(100000, [100000])
>>> len(l)
100000
>>> big_l = cy.Vector.random(1000000, [1000000])
>>> big_l = cy.Vector.random(1000000, [100000000])
>>>

要生成不重复的整数数据,最大值+1 一定要大于等于个数
例子:

cy.Vector.random(100, [99]) # 可以
cy.Vector.random(100, [1234567]) # 可以
cy.Vector.random(100, [10]) # 不行,10+1=11<100
cy.Vector.random(100, [123, 10, 1234]) # 可以,因为123+1=124>100,后面不重要
cy.Vector.random(1_000_000, [1_000_000_000]) # 可以

cyaron/cyaron/vector.py 第69-72行

        if mode == VectorRandomMode.unique and num > vector_space:
            raise ValueError(
                "1st param is so large that CYaRon can not generate unique vectors"
            )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants