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

Bias generated chars (#99) #116

Merged
merged 2 commits into from
Jan 27, 2016
Merged

Conversation

vi
Copy link
Contributor

@vi vi commented Dec 13, 2015

That's how generated strings typically look now:

O���[.?

}'셥-�91(]ª!ñ�·�� #* "9ô�£´�:؀{乸0%㯓9똁⁔Rz릉¤tó£±�? (]>�
<܏nf)_ᖯ'��ñ��°6>¦ó¤�¡匈�#$'`맽ô���c￸HX)�[r莅3_A ð¹�§7]

G_媣<ꉟต8~^i7䱄釱fh)+��{G�0�

ﵽ❔K/5‴9[꤅X1J[M&4[؜¥"

⇉Ɩ©�42폨ĒUñ�¸�5.`'O§)⁣�-���_ñ·�¼‌r ؅
 '@/@�骲6!ñ�§��,&E؀ 
e?!�܏fó � ó¶±¬V�_ (]>el󯣿o+狪_="⁅
￸ñ���肖<{ó¿¿½+巤

{T��_ô�¿½⁆?ó¿¿½ ꡯ칵쫨C}1<ʼn��_���..#ñ��º& J:,j=؂‹3“褙`}j¬ñ���+‌‐󾬲¦bO©￰S�ñ¡��~~�.�ª
=㍃�&f�E&Q@ð¾�±R�笹
⁁�D

6')�m9m�)�sqT�3H㹵0￸35蹈>^鯅ñ��»ó��­�ó¨£�؅�‰쩻8 ⁋0�N\WGô�¡�¥�®��5UWñª���1钟[!�X��+<󿬹難"4​�ó�®³ᔵ"ó¬�®!G

揟’O�1'ñ�¿��+髾@$Zvó�¹�䵃�;ð»�¸�h뢚ស᜼9Yó¿¿¾_L蛇�AjpⰚ�㤩

©揪)ò�®�-d�A){¥攝剟>~ó���؃="

«ó¿¿½1賬‟z⁉�VOô�¿¾�2I!mô�´¿N4;,ñ�¾»i>-\B��)裉᷈�f륯 +ाX~9[u 樴m‿ñ°��!=�=�C[ ط57_£=‴�`⁧5�_�4}⁃‥�у灼 ¥1:�>ð�©»

<$)>@, -"♄f<��ð¶¾�

That's how generated strings typically looks now:

O���[.?

}'셥-�91(]ª!ñ�·��	#* "9ô�£´�:؀{乸0%㯓9똁⁔Rz릉¤tó£±�? (]>�
                                                <܏nf)*ᖯ'��ñ��°6>¦ó¤�¡匈�#$'`맽ô���c￸HX)�[r莅3*A ð¹�§7]

	G_媣<ꉟต8~^i7䱄釱fh)+��{G�0�

ﵽ❔K/5‴9[꤅X1J[M&4[؜¥"

⇉Ɩ©�42폨ĒUñ�¸�5.`'O§)⁣�-���*ñ·�¼‌r ؅
 '@/@�骲6!ñ�§��,&E؀ 
e?!�܏fó � ó¶±¬V�_ (]>el󯣿o+狪*="⁅
     ￸ñ���肖<{ó¿¿½\+巤

{T��*ô�¿½⁆?ó¿¿½ ꡯ칵쫨C}1<ʼn��*���..#ñ��º& J:,j=؂‹3“褙`}j¬ñ���+‌‐󾬲¦bO©￰S�ñ¡��~~�.�ª
=㍃�&f�E&Q@ð¾�±R�笹
⁁�D

6')�m9m�)�sqT�3H㹵0￸35蹈\>^鯅ñ��»ó��­�ó¨£�؅�‰쩻8 ⁋0�N\WGô�¡�¥�®��5UWñª���1钟[!�X��+<󿬹難"4​�ó�®³ᔵ"ó¬�®!G

揟’O�1'ñ�¿��+髾@$Zvó�¹�䵃�;ð»�¸�h뢚ស᜼9Yó¿¿¾_L蛇�AjpⰚ�㤩

©揪)ò�®�-d�A){¥攝剟>~ó���؃="

«ó¿¿½1賬‟z⁉�VOô�¿¾�2I!mô�´¿N4;,ñ�¾»i>-\B��)裉᷈�f륯  +ाX~9[u 樴m‿ñ°��!=�=�C[	ط57_£=‴�`⁧5�_�4}⁃‥�у灼	¥1:�>ð�©»

<$)>@, -"♄f<��ð¶¾�
match mode {
0...49 => {
// ASCII + some control characters
char::from_u32(g.gen_range(0, 0xB0)).expect("I except all characters with codepoints 0 to 255 to be valid")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use the cast from u8 to char to skip both from_u32 and the expect.

BurntSushi added a commit that referenced this pull request Jan 27, 2016
@BurntSushi BurntSushi merged commit faed60d into BurntSushi:master Jan 27, 2016
@BurntSushi
Copy link
Owner

Looks great, thank you!

@BurntSushi
Copy link
Owner

@vi Just wanted to thank you again! This particular patched ended up catching a potential bug in the regex crate!

@vi
Copy link
Contributor Author

vi commented Jan 31, 2016

  1. Shall similar bias be implemented for integer types (especially for big ones like u64)? Now a short test may omit 0 entirely.
  2. Shall there be some specific logic for arrays/vectors to make generation of elements not independent? For example, to make [0; 100] rare instead of almost impossible.

@BurntSushi
Copy link
Owner

I think for integer types the answer is definitely yes. See #119.

I'm not sure whether I want to add a bunch of array impls to this crate (especially up to 100!), but some biasing for vectors seems reasonable too.

@vi
Copy link
Contributor Author

vi commented Jan 31, 2016

For arrays it can be done after language change supporting integer templating and so on. Until then there can be just a dangling opened issue about it.

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

Successfully merging this pull request may close these issues.

3 participants