So here's a ruby implementation of Skip32 by patdeegan:
https://github.com/patdeegan/integer-obfuscator/blob/master/lib%2Fcipher%2Fskip32.rb
I'm currently using this patdeegan/integer-obfuscator to create a non sequential id corresponding to each of my db ids. The thing is, I need this ID to be between 0 and ((2^31)-1) and the above generates ids that go up to ((2^32)-1)
I have little understanding of bitwise operations but this article seems to state they tweaked Skip32 to generate an integer on only 31-bit.
Does someone know how this would need to be adapted and explain it to me ?
Related
In the samples for PCG they only seed one way which I assume is best/preferred practice:
pcg32 rng(pcg_extras::seed_seq_from<std::random_device>{});
or
// Seed with a real random value, if available
pcg_extras::seed_seq_from<std::random_device> seed_source;
// Make a random number engine
pcg32 rng(seed_source);
However running this on my machine just produces the same seed every time. It is no better then if I just typed in some integer to seed with myself. What would be a good method to seed if trying it this way doesn't work ?
pcg_extras::seed_seq_from is supposed to be the recommended way, but it delegates the actual seed generation to the generator specified in the template parameter.
MinGW has a broken implementation of std::random_device. So at this moment, if you want to target MinGW, you must not use std::random_device.
Some potential alternatives:
boost::random_device
randutils, by the author of PCG, M.E. O'Neill
seed11::seed_device, drop-in replacement for std::random_device (disclaimer: it's my own library)
More info about seeding in this blog post by M.E. O'Neill.
Sometimes it is necessary to have tables like:
CREATE TABLE contact_phone_type (
-- PRIMARY KEY
id BIGSERIAL PRIMARY KEY,
-- ATTRIBUTES
name VARCHAR(10) NOT NULL UNIQUE
);
INSERT INTO contact_phone_type
(name)
VALUES
('Phone'),
('Fax');
Which are sometimes annoying to map into enum types in order to have a convenient and typesafe mapping later on. Since those enum types have to be hand written it is sometimes a bit annoying to type the exact same thing a second time. Especially annoying is the case when one changes the ordering. This means that a corresponding email has to be re-ordered by hand as well.
Therefore I am wondering if jOOQs code generator might be able to generate those enums for me instead?
I am aware of this question but my use case if by far not that tricky.
All the generator would have to do is basically look if e.h. the table ends with _type, and if so, create an enum with elements specified e.g. by column name and copy those generated files into a directory I am telling it to.
Is there a chance that this is possible?
Another thing that comes up with those enums is that one has also to write corresponding Converter<>. If the code generator recognizes a "type-table" then it could create the enum and the corresponding converter.
Just a toy example:
private void createDeliveryPhoneNumber(Long shopId, String deliveryPhoneNumber) {
this.ctx
.insertInto(SHOP_CONTACT_PHONE)
.set(SHOP_CONTACT_PHONE.SHOP_ID, shopId)
.set(SHOP_CONTACT_PHONE.PHONE, deliveryPhoneNumber)
.set(SHOP_CONTACT_PHONE.CONTACT_PHONE_TYPE_ID, ContactPhoneType.DELIVERY)
.execute();
}
I am aware of this question but my use case if by far not that tricky.
Apart from the fact that your use-case perception is subjective, and I disagree :), this is equally not available out of the box from jOOQ as the use-case in your linked question (for the same reasons).
It is, however, rather easy to implement this kind of code generation yourself at your end. Either, you can extend the jOOQ code generator to generate additional classes, or you do that in an entirely independent step.
I know this is a strange question, but I have been really confused about this lately.
I have been looking in some repositories in github, and both approaches seem to be used in practise. So, what's the correct way in english grammar to write comments in this pattern?
// create an integer to store the sum.
int i = 1 + 1;
// creates an integer to store the sum.
int i = 1 + 1;
Google's style guide recommends to use third person instead of imperative.
Recommended: tasks.insert: Creates a new task on the specified task list.
Not recommended: tasks.insert: Create a new task on the specified task list.
Your question is probably a duplicate of this one, so take a look over there. I guess, in the end, it's down to your personal preference, whether you use imperative or 3rd person. This is also reflected in the different opinions in the linked question. Just be consistent within your project/organization and everything is fine.
How can I seed Ada.Numerics.Discrete_Random with a discrete value? I see code like:
declare
type Rand_Range is range 25..75;
package Rand_Int is new Ada.Numerics.Discrete_Random(Rand_Range);
seed : Rand_Int.Generator;
Num : Rand_Range;
begin
Rand_Int.Reset(seed);
Num := Rand_Int.Random(seed);
Put_Line(Rand_Range'Image(Num));
end;
which seeds the "Rand_Int" with the "seed" value, but I cannot find any instruction on actually setting the seed value. Or I am completely looking at this the wrong way? I want to set the seed value to a number (like 4 or 5) that I can control to observe test results.
Thanks!
Pass a second Integer argument to Reset. Here it's initiator.
Rand_Int.Reset(seed, initiator);
Ada is one of the few languages with complete, detailed reference manual and rationale available free of charge. Use it! Additionally, here is the more recent Ada version's standard.
Another note: the variable name seed in your code is a terrible choice. A choice like state or generator would be much better.
NB: Ada is really a very nice language in many respects. People gripe about the very strong, detailed type system. Then when the system's done and it runs first try with few bugs, they mysteriously forget to attribute it to Ada. The significant down sides are library availability and maturity of IDEs.
How do I get the sorted o/p using Hadoop mapreduce programming.
Is there any way to get final key-value pair in sorted order. ( either by key or value).
Any pointers on this greatly appreciated.
Thank You
R
By default, MapReduce will sort input records by their keys.
However, it might help you more to download latest Hadoop release and check out examples they have. There are different sort examples as well.
If you need more information on sort order, this is how it can be changed.
The sort order for keys is controlled by a RawComparator, which is found as follows:
If the property mapred.output.key.comparator.class is set, an instance of that class
is used. (The setOutputKeyComparatorClass() method on JobConf is a convenient
way to set this property.)
Otherwise, keys must be a subclass of WritableComparable, and the registered
comparator for the key class is used.
If there is no registered comparator, then a RawComparator is used that deserializes
the byte streams being compared into objects and delegates to the WritableCompar
able’s compareTo() method.
These rules reinforce why it’s important to register optimized versions of RawCompara
tors for your own custom Writable classes, and also that it’s straightforward to override the
sort order by setting your own comparator.
"Hadoop: The Definitive Guide" 2nd edition describes global sort in chapter 8 with code samples.