Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4620592
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:34:53+00:00 2026-05-22T02:34:53+00:00

I was wondering how to get a random Unicode character so that every time

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T02:34:54+00:00Added an answer on May 22, 2026 at 2:34 am

    If you truly want a random character, something like

    UniChar uc = arc4random() % (0xffffu + 1);        
    CTFontGetGlyphsForCharacters((CTFontRef)arialUnicode, &uc, (CGGlyph *)glyphs, 1);
    

    But depending on what you are trying to do

    • There are much easier ways to display text in Cocoa, particularly NSTextField
    • There are so many characters in Unicode it’s highly unlikely a single font will contain all the glyphs.

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am wondering how to get a process run at the command line to
I have some code that at one part will get executed a lot, and
I have this really random problem with is bugging me. It works at the
I was wondering what the way is to get a random number with a
I have some random HTML layouts that contain important text I would like to
Hey guys, what i have now is this: var Human=function(){ this._a=Math.random(); }; (function() {
I was wondering if I could get some refactoring help to make this query
I am wondering where I can get this pattern in Xcode? Thanks!
I was wondering if in Java I would get any odd behaviour if I
I was wondering if anyone can help me get started with creating a room

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.