I was wondering how to get a random Unicode character so that every time this is run it generates a different value. This is what I have so far to get a character:
NSFont *arialUnicode = [[NSFontManager sharedFontManager]
fontWithFamily:@"Arial Unicode MS"
traits:0
weight:5
size:dirtyRect.size.height*0.6];
NSGlyph *glyphs = (NSGlyph *)malloc(sizeof(NSGlyph) * 1);
CTFontGetGlyphsForCharacters((CTFontRef)arialUnicode, (const UniChar *)L"\u2668", (CGGlyph *)glyphs, 1);
It is adapted from a drawing tutorial my friend sent me: http://cocoawithlove.com/2011/01/advanced-drawing-using-appkit.html
Quite a nice tutorial actually 🙂
But I want to know how to use any character as opposed to just the floral heart. I have found that buy changing the value of 2668 to some other value in the line:
CTFontGetGlyphsForCharacters((CTFontRef)arialUnicode, (const UniChar *)L"\u2668", (CGGlyph *)glyphs, 1);
I can make it change character but i want to automate this so that it automatically chooses different characters.
Thank you
If you truly want a random character, something like
But depending on what you are trying to do
Do you really want a random unicode code point or do you want to select from a subset of the available characters? See http://www.unicode.org/charts/ to get an idea of just how much Unicode covers.