Modifying a Cohen generic Let $M$ be a transitive model of ZFC (set- or class-sized) and let $\kappa\in M$ be a regular cardinal (in $V$). Let $G$ be $M$-generic for $\operatorname{Add}(\kappa,1)$. Now suppose that there is an $X\subseteq\kappa$ of size $\kappa$ which has no size $\kappa$ subsets in $M$ (for example, we could take $X=G$).
My question concerns which "patterns" can be realized in an $M$-generic on the coordinates in $X$.

Given a subset $Y\subseteq X$, is there an $M$-generic $G'$ for $\operatorname{Add}(\kappa,1)$ such that $G'\cap X=Y$? In other words, if we see $Y$ as a pattern of 0s and 1s, is there a generic $G'$ whose pattern on $X$ matches $Y$?

The requirement that $X$ has no large subsets in $M$ is clearly necessary: if $X'\subseteq X$ is in $M$ and has size $\kappa$, a density argument shows that $G'\cap X'\neq \emptyset$ for any generic $G'$, preventing us from realizing the all 0 pattern $Y=\emptyset$.
Certain patterns can be easy to achieve. For example, if we take $X=G$, then it is simple to realize the all 1 pattern $Y=G$: just take $G'=G$. Similarly, the all 0 pattern $Y=\emptyset$ is realized by $G'=\kappa\setminus G$. This last example also shows that it does not suffice, in general, to simply perform surgery on $G$ on the coordinates in $X$ and that global changes to $G$ might be necessary.
I am particularly interested in the special case when $M$ is the ultrapower by a measure on a measurable cardinal $\lambda$, we have $\kappa=\lambda^+$ and GCH holds. In this situation there is a variety of $M$-generics in $V$, which might make the problem easier.
 A: In some cases, it is possible to construct a set $X$
for which every pattern $Y\subseteq X$ is realized in the way you
describe.
For example, consider the very natural case where $M$ is a
countable transitive model of ZFC and $\kappa=\omega$. So we are
talking about adding $M$-generic Cohen reals here. Enumerate the
dense subsets $D_0,D_1,\ldots$ of $M$, and let us build a generic
$G$ by diagonalization, while also constructing $X$ for which any
$Y\subseteq X$ is realized. Construct a descending sequence of
conditions $p_0\geq p_1\geq\dots$ as follows. Let $p_0$ be any
element of $D_0$. Now, let the first element $i_0$ of $X$ be the
first unspecified bit of $p_0$. Let $\bar p_1$ extend $p_0$ into $D_1$, and then flip the bit at $i_0$ in $\bar p_1$ and
further extend to $p_1$ in $D_1$. So $p_1\in D_1$, extending $p_0$, and
flipping the bit at $i_0$ keeps the condition in $D_1$. Continue similarly. At stage $n$, let $i_n$ be the first unspecified bit of
$p_n$; first extend to $\bar p_{n+1}$ into $D_{n+1}$, and then flip
the bits at all the $i_k$ for $k\leq n$ in any desired pattern, and
extend into $D_{n+1}$ again, repeating for each pattern. At the
end, let $p_{n+1}$ be the resulting extension of $p_n$, which has
all its finite flips on the $i_k$'s in $D_{n+1}$. Let $G$ be the
filter generated by the conditions $p_n$, which is $M$-generic
since we have met every dense set, and let $X$ be the set of all
$i_n$. By design, for any bit-flipping pattern on $X$, the
construction exactly arranges that the resulting filter obtained by
surgery will also be $M$-generic. Thus, every pattern $Y\subseteq
X$ is realized by some $M$-generic surgical modification of $G$.
Update. Let me explain how a similar idea can work higher up, such as in
the case of your ultrapower, with some additional assumptions.
Specifically, let's assume that $\kappa$ is a regular cardinal and
$M$ is a transitive set or class model of ZFC, with
$M^{<\kappa}\subset M$ and $|P(\kappa)^M|=\kappa$, which is true
for your ultrapower example at the end of the question, if we have
the GCH at your measurable cardinal. These assumptions are enough
to construct $M$-generic Cohen sets $G\subset\kappa$ by the usual
diagonalization procedure. You enumerate in $V$ the dense sets of
$M$, and then construct a descending $\kappa$-sequence that gets
inside them.
But let me now assume additionally that the $\Diamond_\kappa$
principle holds in $V$. In this case, I shall construct a set
$X\subseteq\kappa$ such that every pattern $Y\subseteq X$ is realized in
the way you request. Fix a $\Diamond_\kappa$-sequence $\langle
A_\alpha\mid\alpha<\kappa\rangle$. Enumerate the dense sets of $M$
as $D_\alpha$, for $\alpha<\kappa$. At stage $\alpha$ of the
construction, we have constructed a descending sequence of
conditions $p_\beta$ for $\beta<\alpha$, and we have identified the
first $\alpha$ many elements of $X$. Let $\bar p_\alpha$ be the
union of the prior conditions, which is a condition in $M$ because
$M^{<\kappa}\subset M$. We only do something special if the domain
of $\bar p_\alpha$ is $\alpha$ itself, and if furthermore
$A_\alpha$ is coding an ordinal $\beta<\kappa$ and a subset $Y$ of
the first $\alpha$ members of $X$. In this case, we first extend
$\bar p_\alpha$ into $D_\beta$, and then we further extend to a
condition $p_\alpha$, so that after flipping the bits on $Y$, the
condition remains in $D_\beta$. After this, let the $\alpha^{th}$
member of $X$ simply be the first bit unspecified by $p_\alpha$.
By design, the filter $G$ generated by the descending sequence of
conditions $p_\alpha$ is an $M$-generic filter. If $Y\subseteq X$
is any set, then let $G_Y$ be the filter obtained by flipping the
bits of $G$ on the coordinates of $Y$. This filter is also
$M$-generic, since for any dense set $D_\beta$, there is a
stationary set of stages $\alpha$ for which the domain of the
conditions up to $\alpha$ is $\alpha$ itself (since that occurs on
a club) and where $A_\alpha$ codes $\beta$ and the set
$Y\cap\alpha$. In this case, the condition $p_\alpha$ had the
property that flipping the bits on $Y$ remained in $D_\beta$, and
so $G_Y$ meets $D_\beta$. Thus, any desired pattern can be arranged
on the digits of $X$, by choosing $Y$ suitably.
